0
votes

I'm curious about a good way to do login with CodeIgniter.

I am currently trying the following: - Take a user's email and password from the login form - Encrypt that password, and compare it to the one in the DB.

However it returns false. I believe it is because the encryption method creates a new encrypted password every time.

I believe this is a good thing, but the only other way I can see to do a login is as follows:

  • When the user submits the form to login, the form is validated
  • The user in the DB with a matching username (or email address) is pulled and stored in a variable.
  • The password that was pulled out is then decrypted and compared with the user trying to login

I am uncomfortable with this because it requires me to store an unencrypted password in a variable, potentially requiring a good hacker to only know a user's email address.

Suggestions?

2
suggestions, use Third Party API's/libraries for login why? (1)Community/Peer viewed,(2)Less time codeing,(3)There is always that certain security hole you think you got figured out. But did not, (4)Updated. - tomexsans
Nice. Any you would recommend? - JDillon522
Oauth,TankAuth,IonAuth to name a few - tomexsans

2 Answers

0
votes

When user register you can store password & it's salt by using php crypt i.e. crypt($password, $salt) where $password is user entered password & $salt is random string. Now, At the time of login

  1. When the user submits the form to login, the form is validated
  2. The user in the DB with a matching username (or email address) is pulled.
  3. The password that was pulled out is take into $hashed_password & user entered into the $password then compare

    if (crypt($password, $hashed_password) == $hashed_password) 
    {
    //successful login
    }else{
    //Invalid username/password
    }
    
0
votes

You chould also use the form_validation rules using

$this -> form_validation -> set_rules('passconf', 'Re-enter', 'required|matches[password]');
#the rules set as the 3rd parameter of the set_rules function have matches