Exactly as Andopes stated. Here's the function in Sugar used to save the password:
PHP Code:
function change_password($user_password, $new_password) {
global $mod_strings;
global $current_user;
$GLOBALS['log']->debug("Starting password change for $this->user_name");
if (!isset ($new_password) || $new_password == "") {
$this->error_string = $mod_strings['ERR_PASSWORD_CHANGE_FAILED_1'].$current_user['user_name'].$mod_strings['ERR_PASSWORD_CHANGE_FAILED_2'];
return false;
}
$old_user_hash = strtolower(md5($user_password));
if (!is_admin($current_user)) {
//check old password first
$query = "SELECT user_name FROM $this->table_name WHERE user_hash='$old_user_hash' AND id='$this->id'";
$result = $this->db->query($query, true);
$row = $this->db->fetchByAssoc($result);
$GLOBALS['log']->debug("select old password query: $query");
$GLOBALS['log']->debug("return result of $row");
if ($row == null) {
$GLOBALS['log']->warn("Incorrect old password for ".$this->user_name."");
$this->error_string = $mod_strings['ERR_PASSWORD_INCORRECT_OLD_1'].$this->user_name.$mod_strings['ERR_PASSWORD_INCORRECT_OLD_2'];
return false;
}
}
$user_hash = strtolower(md5($new_password));
//set new password
$query = "UPDATE $this->table_name SET user_hash='$user_hash' where id='$this->id'";
$this->db->query($query, true, "Error setting new password for $this->user_name: ");
return true;
}
Bookmarks