Сначала я сохраняю пароль при создании пользователей, используя:
Код: Выделить всё
$options = ['cost' => 10];
password_hash($data['password'], PASSWORD_DEFAULT, $options)
неправильный пароль
Код: Выделить всё
public function login() {
$email = trim($this->input->post('email'));
$password = trim($this->input->post('password'));
log_message('info', 'Login attempt with email: ' . $email);
$user = $this->db->get_where('users', ['email' => $email])->row();
if ($user) {
log_message('info', 'User found: ' . json_encode($user));
if (password_verify($password, $user->password)) {
// Check if rehash is needed and update the password hash if required
if (password_needs_rehash($user->password, PASSWORD_DEFAULT, ['cost' => 10])) {
$newHash = password_hash($password, PASSWORD_DEFAULT, ['cost' => 10]);
// Logging hash update
log_message('info', 'Rehashing password for user: ' . $email);
// Update database with the new hash
$this->db->update('users', ['password' => $newHash], ['email' => $user->email]);
}
// Session setup and role-based redirection (as in your code)
// ...
} else {
log_message('error', 'Password verification failed for email: ' . $email);
$this->session->set_flashdata('error', 'Incorrect password provided. Please try again.');
redirect(base_url());
}
} else {
log_message('error', 'Email not found: ' . $email);
$this->session->set_flashdata('error', 'Email not found. Please try again.');
redirect(base_url());
}
}
Каково решение этой проблемы? Или, если у вас есть другой стабильный хэш-код пароля, пожалуйста, помогите мне.
Подробнее здесь: https://stackoverflow.com/questions/791 ... ord-verify
Мобильная версия