Return to Snippet

Revision: 65332
at November 20, 2013 14:55 by luckygreentiger


Initial Code
/* the salt, in this case is determined by the second letter of the
password. the string position can be changed in $strPass[x] and of course
the salts can be changed to different values. standard disclaimers
apply. not promised to work. take the code as-is. if you like, find
errors, or use please let me know at luckygreentiger at gmail */

    function hashPassword($strPass) {
        $value = $strPass[1];
            if(preg_match("/^[a-f]+/i", $value)) {
                $salt = "!";
                }
            else {
                $salt = "#";
                }
            if(preg_match("/^[g-m]+/i", $value)) {
                $salt = "@";
                }
            if(preg_match("/^[n-s]+/i", $value)) {
                $salt = "$";
                }
            if(preg_match("/^[t-z]+/i", $value)) {
                $salt = "%";
                }
 
            $strPass .= $salt;
        $hash = hash("sha512", $strPass); // sha512 is 128 characters
        return $hash;
        }

Initial URL

                                

Initial Description
An attempt for a semi-random salt in a stored password. It's not stored in the database so I believe it would be harder to discover. Samples should be changed.

Initial Title
Function to hash passwords

Initial Tags
php

Initial Language
PHP