$salt = substr(md5(uniqid(rand(), true)), 0, 22);
$crypt = \Bcrypt::instance();
$password = $crypt->hash($this->f3->get('POST.password')[$salt]); //error here
$this->f3->set('POST.salt', $salt);
$this->f3->set('POST.password', $password);
$user = new User($this->db);
$user->add();
This seems weird to me...
How would I get the salt back from the db? Should I first query the database for the salt, check the password with this and then do a second query to see if the hash is correct? Or is it possible to check with one query only?
v.
$password = $crypt->hash($this->f3->get('POST.password').$salt);
How would I get the salt back from the db? Should I first query the database for the salt, check the password with this and then do a second query to see if the hash is correct? Or is it possible to check with one query only?
$valid = \Bcrypt::instance()->verify($f3->get('POST.password').$user->salt, $user->password);
if ($salt) {
...
}
else {
$raw=16;
$iv='';
if (extension_loaded('mcrypt'))
$iv=mcrypt_create_iv($raw,MCRYPT_DEV_URANDOM);
if (!$iv && extension_loaded('openssl'))
$iv=openssl_random_pseudo_bytes($raw);
if (!$iv)
for ($i=0;$i<$raw;$i++)
$iv.=chr(mt_rand(0,255));
$salt=str_replace('+','.',base64_encode($iv));
}$user = new \DB\SQL\Mapper($this->db, 'users');
$user->load(['username=?', $this->f3->get('POST.username']);
if($user->dry()){
die( 'username does not exisit');
}
if(!\Bcrypt::instance()->verify($this->f3->get('POST.password'), $user->password){
die('password incorrect';
}
//verified, good to go
echo 'Welcome back ' . $user->name;$crypt = \Bcrypt::instance();
$password = $crypt->hash($this->f3->get('POST.password')); //no salt given -> salt = generated automatically
$user = new \DB\SQL\Mapper($this->db, 'users');
$user->load( [ 'username=?', $this->f3->get('POST.username') ] );
if($user->dry()){die( 'username does not exist');}
if(! \Bcrypt::instance()->verify($this->f3->get('POST.password'), $user->password)){
echo $this->f3->get('POST.password').' - '.$user->password .'<br />';
die('password incorrect');
}
echo 'Welcome back ' . $user->username;