2014-10-08 47 views
-1

我在努力检索code,将它添加到另一个密码,散列它然后将其与数据库中存储的密码进行比较。它的网站已经存在,我只是迁移code获取用户代码,添加密码并对其进行散列。 Codeigniter/php

code是用户创建帐户时生成的一个随机数,它对它们是唯一的,所以它就像第二个密码。并且使其不可能哈希哈希。你可能已经猜到了,我打电话和查询同样的事情两次,我只是不确定我怎么能解决这个问题。

任何帮助将是好的,谢谢。

回答

0

你在做什么叫做Salt

例子。

$q= $this->db->get_where('users', array('username' => $user), 1); 
if($q->num_rows === 0) 
    return false; //username not found 

$user = $q->first_row(); 
if($user->password !== md5($user->code.$password)) 
    return false; // password is not correct. 
//for debugging 
//return "{$user->password} is not equal to ".md5($user->code.$password); 

//if u r here then pass and username matchs 
return $user; 
+0

嗨,它没有返回一个错误,但返回一个无效的密码/用户名。有什么想法? – Bakitai 2014-10-08 10:57:47

+0

yp; 'md5(password。$ user-> code)'应该是'md5($ user-> code.password);'不要忘记upvote/accept如果它解决你的问题:) – Zalaboza 2014-10-08 14:07:20