Advertisement
reenadak

password encoder

Feb 20th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1.     /*
  2.     - Password Encoder
  3.     - Encodes a password so it cannot be converted back into plain text by anyone
  4.       that has access to the database.
  5.      
  6.     $password     - The plain text password that was entered by the user for encoding
  7.     $salt         - Optional but recommended, "salts" the password to make it even harder
  8.                     to be decoded. Can be generated with the function generateSalt()
  9.     $hashType     - Default is sha512, the hashing algorithm to use between:
  10.                     sha1, sha256, sha512, ripemd160
  11.     */
  12.    
  13.     public function encodePassword($password, $salt = '', $hashType = 'sha512') {
  14.         if ($hashType != "sha1" && $hashType != "sha256" && $hashType != "sha512"
  15.             && $hashType != "ripemd160")
  16.             $hashType = "sha512";
  17.        
  18.         if ($salt == '')
  19.             $password = hash($hashType, $password);
  20.         else
  21.             $password = hash($hashType, $salt . $password . $salt);
  22.        
  23.         return $password;
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement