English 中文(简体)
php散列函数检查数据库
原标题:php hash function checking database
  • 时间:2011-05-30 13:20:14
  •  标签:
  • php
  • sql
  • oop

当把一个新用户插入数据库时,我想散列密码。这就是我所拥有的。

    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; 
}

当我打印或var转储$lastID时,我得到13。然而,在数据库中,我只有一个ID为1的用户。我甚至缩短了表格,但我仍然得到了13。不知道为什么。

基本上,我的想法是,我想把$lastID附加到密码中,这样就更难逆转了。出于登录目的,我需要知道下一个ID是什么。

最佳回答
$result = $database->query($sql);           
return $result; 

您返回的是结果资源,而不是实际数据(我认为是这样,除非$database模块自动执行此操作),否则您可能希望:

$result = $database->query($sql);    
$data = mysql_fetch_array($result);
return $data[ ID ]; 
问题回答

暂无回答




相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签