Welcome Guest, Not a member yet? Register   Sign In
hash function not working at all...
#1

[eluser]Unknown[/eluser]
can someone please tell me why this is not working?

Code:
class User_Model extends Model {
    
    function validateLogin() {
        $this->db->where('email', $this->input->post('email'));
        $this->db->where('hash', hash('sha512', $this->input->post('password')));
        $q = $this->db->get('login');
        if($q->num_rows() == 1) {
            return true;
        }
    }
}

I created a script outside the CI installation and used the hash function successfully there, but I can't inside the model, why? Sad
#2

[eluser]Clooner[/eluser]
Probably the input isn't exactly the same. Try using the trim command to remove any spaces from the password and compare the two inputs. Also it is a good idea to salt the passwords with an extra secret key
#3

[eluser]danmontgomery[/eluser]
What does "not working" mean?
#4

[eluser]Clooner[/eluser]
and also you can't call $this->input->post('password') from the model directly. Pas it as a variable in the function
#5

[eluser]mddd[/eluser]
@clooner: That is not true. You can use $this->input in models just fine.

I do agree with your earlier remark. Gjore.S should check if the provided data comes through correctly.

And, as noctrum says, it would be good to have more information on exactly what goes wrong.
Just saying "it doesn't work" is not enough.
For instance, if there are two records in the database with the correct email address and password, the query will give 2 results.
And therefore login validation will fail. The problem could be in other places than the hash() function or even the entire model.
#6

[eluser]Unknown[/eluser]
I got it fixed, it turned out that the login form wasn't posting input to the correct controller.

About the hashing, I use triple salting in production-ready code, this one was just for testing.

something like:
Code:
$pass = hash('sha512', $pass.$salt1.$pass);
$pass = hash('sha512', $salt2.$pass.$pass);
$pass = hash('sha512', $pass.$pass.$salt3);




Theme © iAndrew 2016 - Forum software by © MyBB