0
votes

I have created a signup form using the codeigniter encryption library to store the users passwords as follow:

$encrypted_password = $this->encrypt->encode($this->input->post('password')); 

I have notice that each time we encrypt (event if we encrypt the same password) the encryption function it produce a different output.

My question is the follow: What is the best way to compare the two encrypted passwords when the user try to login on the system as we know that each time we encrypt we get a different encrypted string?

1

1 Answers

0
votes

Look here: https://ellislab.com/codeigniter/user-guide/libraries/encryption.html

$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';

$plaintext_string = $this->encrypt->decode($encrypted_string);

The encription class is using the symetric encoding. So to compare you have to decrypt the password and compare it. If you want to use a one way method use hashing, Correct me if I'm wrong but codeigniter supports only up to sha1, so maybe look here for what native php has to offer: http://php.net/manual/en/function.hash.php

You could also combine both methods, hash and than encrypt.