Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I hash passwords in CodeIgniter

I started to use Codeigniter framework and in their new release doc's they say

DO NOT use this or any other encryption library for user password storage! Passwords must be hashed instead, and you should do that via PHP’s own Password Hashing extension.

The problem is that I use PHP 5.3 and that extension requires 5.5

What should i use for hashing in PHP 5.3?

like image 652
AAron Avatar asked Sep 26 '15 15:09

AAron


People also ask

How is a password hashed?

Hashing turns your password (or any other piece of data) into a short string of letters and/or numbers using an encryption algorithm. If a website is hacked, cyber criminals don't get access to your password. Instead, they just get access to the encrypted “hash” created by your password.

How can I see my password in codeigniter?

php echo form_input(array('placeholder'=>'Confirm your password', 'type'=>'password', 'name'=>'confirm_password')); ?> Show activity on this post. Show activity on this post.


1 Answers

private function hash_password($password){
   return password_hash($password, PASSWORD_BCRYPT);
}
public function registerUser($username,$email,$password){
   $data = array(
     'username' => $username,
      'email' => $email,
     'password' => $this->hash_password($password)
);
return $this->db->insert('table_name', $data);
}

PASSWORD_BCRYPT - Use the CRYPT_BLOWFISH algorithm to create the hash. This will produce a standard crypt() compatible hash using the "$2y$" identifier. The result will always be a 60 character string, or FALSE on failure.
Source: http://php.net/manual/en/function.password-hash.php

like image 178
Mau Xanh Cua Linh Avatar answered Nov 15 '22 11:11

Mau Xanh Cua Linh