我的问题..变量$ salted返回一个随机的UUID然后是md5它。我需要登录才能使用变量$ salted来返回我的数据库中的passwordSalt字段的值与t1.PrincipalID = t2.UUID
对应的auth表。如何给变量$ salted这个值?
基本上如何在没有用户输入的情况下从数据库中为变量赋值。谢谢。
代码片段......我的代码的重要部分。
我的观点......
<?php echo validation_errors(); ?>
<?php echo form_open('verifylogin'); ?>
<form>
<input type="text" name="FirstName" placeholder="firstName">
<input type="password" name="passwordHash" placeholder="Password">
<input type="submit" name="login" class="login login-submit" value="Login">
</form></div>
我的控制员......
Function check_database($password)
{
//Field validation succeeded. Validate against database
$firstName = $this->input->post('FirstName');
$password = $this->input->post('passwordHash');
//query the database
$result = $this->users_model->login($firstName,$password);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
'PrincipalID' => $row->PrincipalID,
'FirstName' => $row->FirstName
);
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message('check_database', 'Invalid username or password');
return false;
}
}
我的模特..
function login($firstName,$password)
{
$salted = sprintf('%s', md5(_uuid()));
$hash = md5(md5($password) . ":" . $salted);
$this->db->select('PrincipalID, FirstName')
->from('useraccounts AS t1, auth AS t2')
->where('t1.PrincipalID = t2.UUID')
->where('t1.FirstName', $firstName)
->where('t2.passwordHash', $hash);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}