Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password Hash Implementation

I am developing a new application using Symfony. I want to store the passwords hashed, so I overridded the save method in my User model:

public function save(Doctrine_Connection $conn = null)
{
    $this->setUserPassword( md5($this->getUserPassword()) );
return parent::save($conn);
}

This works good when a new user created. However, this causes problems when we edit a user without changing his password. This causes Doctrine to hash the already hashed password.

So, I need to check that whether the UserPassword is modified in this DoctrineRecord instance. How can I manage to do that?

like image 434
user340538 Avatar asked May 10 '26 02:05

user340538


1 Answers

Solution: We need to override the setter method only:

public function setUserPassword($password)
{
    return $this->_set('user_password', md5($password));
}
like image 108
user340538 Avatar answered May 11 '26 17:05

user340538