password_hash
Olá,
Estou com muita dificuldade em inserir e atualizar a senha usando o método password_hash. Alguém poderia me explicar como eu posso fazer isso? Tenho um crud, ele funciona perfeitamente, mas quero implementar o password_hash na senha. Como fazer isso?
<?php
require_once 'Crud.php';
class Usuarios extends Crud {
protected $table = 'usuarios';
private $nome;
private $email;
private $senha;
public function setNome($nome) {
$this->nome = $nome;
}
public function getNome() {
return $this->nome;
}
public function setEmail($email) {
$this->email = $email;
}
public function setSenha($senha) {
$this->senha = $senha;
}
public function insert() {
$sql = "INSERT INTO $this->table (nome, email, senha) VALUES (:nome, :email, :senha)";
$stmt = DB::prepare($sql);
$stmt->bindParam(':nome', $this->nome);
$stmt->bindParam(':email', $this->email);
$stmt->bindParam(':senha', $this->senha);
return $stmt->execute();
}
public function update($id) {
$sql = "UPDATE $this->table SET nome = :nome, email = :email, senha = :senha WHERE id = :id";
$stmt = DB::prepare($sql);
$stmt->bindParam(':nome', $this->nome);
$stmt->bindParam(':email', $this->email);
$stmt->bindParam(':senha', $this->senha);
$stmt->bindParam(':id', $id);
return $stmt->execute();
}
}
#Edit:
Pensei em adicionar isso, mas não resultou, o que estou fazendo de errado?
public function hash($senha) {
$options = [
'cost' => 11,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)
];
return password_hash($senha, PASSWORD_BCRYPT, $options);
}
public function verificarPassword($senha, $hash) {
if(password_verify($senha, $hash)) {
return true;
}
return false;
}Discussão (7)
Carregando comentários...