开发者

php hash function checking database

When inserting a new user into a database i want to hash the password. this is what i have got.

    static function getLastId(){
        global $database; 
        $sql = 'SELECT ID from users ORDER BY id DESC LIMIT 1' ;
        $result = $database->query($sql);           
        return $result; 
    }


static function create_user($username,$password ){
    global $database;
    $lastID =  self::getLastId() + 1;       
    $ePassword = $database->escape_value($password);
    $hash = hash('sha256', $lastID . $ePassword);
    $sql = "INSERT INTO ". self::$table_name . " (username, password, first_name, last_name, power ) VALUES ";
    $sql .= "('{$database->escape_value($username)}', '{$hash}', 'asd' , 'asd', 'user') ";
    $query = $database->query($sql);
    return ($query)? true : false; 
}

when i do a print or var dump of $lastID I get 13. however looking a the database i only have 1 user me, with an ID of 1. I even truncated the table, but i am still getting 13. not sure why.

basically the idea is that i want to append $lastID to开发者_Python百科 the password, so that it is much harder to reverse. I need to know what the next ID is going to be, for login purposes.


$result = $database->query($sql);           
return $result; 

You're returning the result resource instead of actual data (i assume so, unless your $database module automatically does this), you might want to:

$result = $database->query($sql);    
$data = mysql_fetch_array($result);
return $data['ID']; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜