'Remember Me' login in CodeIgniter |
[eluser]Mowgli[/eluser]
Thank you bretticus ! Instead of creating a new class I simply called a function I made from within the constructor of my default controller. I thought about using something like Tank Auth but since I'm pretty new into Codeigniter I'd rather write stuff from scratch... this way I learn something new every day. I went for your solution and I also encrypted the password with sha1. I checked the cookie value (from browser) and the CI encryption worked fine as well but now I'm facing another problem. I don't know how to retrieve cookie's VALUE so I could decrypt and explode the variables stored inside (sha1 password and id). I double checked the codeigniter documentation (which is usually enough) but I couldn't find what I was looking for.
[eluser]bretticus[/eluser]
I think I understand what you are saying... You can't hash any plain text that you need to decrypt before encrypting it because a decrypted hash is still one-way encryption. So make sure you have a decipherable string BEFORE you encrypt it. The password is probably (or probably should be) already a sha1 or md5 hash. Which means after decrypting the string (see the Encryption Class) you'll have (at least) the user id and the password hash. From there, simply look for a user record with the same id and hash for the password. EDIT: Oh, you just need to get the cookie?? Well, CI provides a Cookie Helper, but you can also just use PHP's $_COOKIE super global and setcookie to store it in the first place. The CI functions are kind of nice (my example uses it. sorry.) to abstract a few details out of the process. You just use the same name in your get/set_cookie functions (or you can use the Input Class.)
[eluser]Mowgli[/eluser]
Yes, I got that from the first time you mentioned it. The problem was something else: My initial code: Code: $cookie = array( When I was trying to echo out the encrypted value (just to test it): $encrypted_string = $this->input->cookie('bids'); nothing was stored into $encrypted_string. After much brainstorming I realised the problem was the last parameter from the cookie array: So the new code became: Code: $cookie = array( Now when I echo out I get exactly what I have expected. If I decode and then explode what I previously imploded (with | separator) I end up with the id and sha1 password. Exactly what I intended. This pretty much solved the problem. Thanks again for your help ! LE: yes, I actually tested both cookie helper and $_COOKIE super global but nothing seemed to work since the problem was something else. And it took me some time to figure out what the real problem was. |
Welcome Guest, Not a member yet? Register Sign In |