reenadak icon

password encoder

reenadak | PRO | 02/20/18 07:03:16 PM UTC | 0 ⭐ | 365 👁️ | Never ⏰ | []
PHP |

890 B

|

None

|

0 👍

/

0 👎

    /*
    - Password Encoder
    - Encodes a password so it cannot be converted back into plain text by anyone
      that has access to the database.
      
    $password     - The plain text password that was entered by the user for encoding
    $salt         - Optional but recommended, "salts" the password to make it even harder
                    to be decoded. Can be generated with the function generateSalt()
    $hashType     - Default is sha512, the hashing algorithm to use between:
                    sha1, sha256, sha512, ripemd160
    */
    
    public function encodePassword($password, $salt = '', $hashType = 'sha512') {
        if ($hashType != "sha1" && $hashType != "sha256" && $hashType != "sha512"
            && $hashType != "ripemd160")
            $hashType = "sha512";
        
        if ($salt == '')
            $password = hash($hashType, $password);
        else
            $password = hash($hashType, $salt . $password . $salt);
        
        return $password;
    }

Comments