密码存储/检查类。确保密码安全。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了密码存储/检查类。确保密码安全。相关的知识,希望对你有一定的参考价值。
Nice implementation of Blowfish for storing user passwords to prevent decryption when for example the user database is compromised. Origin: Burak [email protected]
// // PassHash.php (Utility class): // class PassHash { // blowfish private static $algo = '$2a'; // cost parameter private static $cost = '$10'; // mainly for internal use public static function unique_salt() { } // this will be used to generate a hash self::$algo . self::$cost . '$' . self::unique_salt()); } // this will be used to compare a password against a hash public static function check_password($hash, $password) { return ($hash == $new_hash); } } /////////////////////////////////////////////////////////////////// // // Usage during registration (creating a new user record) : // /////////////////////////////////////////////////////////////////// // include the class require ("PassHash.php"); // read all form input from $_POST // ... // do your regular form validation stuff // ... // hash the password // store all user info in the DB, excluding $_POST['password'] // store $pass_hash instead // ... /////////////////////////////////////////////////////////////////// // // Usage during login (checking the user record) : // /////////////////////////////////////////////////////////////////// // include the class require ("PassHash.php"); // read all form input from $_POST // ... // fetch the user record based on $_POST['username'] or similar // ... // check the password the user tried to login with if (PassHash::check_password($user['pass_hash'], $_POST['password'])) { // grant access // ... } else { // deny access // ... }
以上是关于密码存储/检查类。确保密码安全。的主要内容,如果未能解决你的问题,请参考以下文章
Python练习题9(密码判断):请写一个密码安全性检查的代码代码: 首先判断密码的强度,如果结果是低或中则打印如何提升密码安全级别的提示,而高则直接退出