/ Published in: PHP
![](/img/icon_sav.png?v3)
Simple password hashing function without recursion using a salt, that is stored together with the password.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Generate salted password, using new salt or exiting one from the password itself. * * @param string $plainTextPassword * @param string $salt default = NULL (create new salt) * @param int $saltLength default = 9 (the salt is the first X chars of the password hash) * @return string password-hash */ function passwordHash( $plainTextPassword, $salt = null, $saltLength = 9 ) { { // create new salt } else { } } /* create new password */ $newPassword = passwordHash( 'plaintext_password_from_user_input', null ); /* check given plaintext password against hashed one from database */ // query the password hash from the database; $row is a single result row if( $row['password'] == passwordHash( 'plaintext_password_from_user_input', $row['password'] ) ) { /* the users password was correct, login successful */ }
Comments
![RSS Feed for Comments RSS Icon](/images/rss.png?v3)