Cześć. Uczę się obecnie obiektowego PHP i napotkałem problem. Otóż w funkcji insert_user() chcę włożyć zahaszowane hasło, które jest haszowane w funkcji hash_password(). Wiem że na pewno jest jakiś sposób na to, bo przecież po co robić haszować hasło w nastepnej funkcji skoro zrobiłem to wcześniej. Mam nadzieję że ktoś mi pokaże wskazówki.
public function hash_password()
{
$field = $this->data['password'];
$hash = password_hash($field, PASSWORD_DEFAULT);
}
public function Insert_user()
{
$field1 = $this->data['login'];
$field2 = $this->data['password'];
$field3 = $this->data['first_name'];
$field4 = $this->data['last_name'];
$field5 = $this->data['email'];
$field6 = $this->data ['birth_date'];
$field7 = $this->data['gender'];
$field8 = $this->data['number_phone'];
$field9 = $this->data['gender'];
$field10 = $this->data['avatar'];
$field20 = date("Y-m-d");
$field100 = date('H:i:s');
$field30 = strtotime($field6);
$field40 = strtotime($field20);
$age = $field40-$field30;
$age10 = $age/(60*60*24*365);
if(empty($this->errors))
{
$sql = $this->database->connect()->prepare("INSERT INTO users(`login`, `password`, `first_name`, `last_name`, `email`, `birth_date`, `age`, `number_phone`, `gender`, `avatar`) VALUES(:login, :password, :first_name, :last_name, :email, :birth_date, :age, :number_phone, :gender, :avatar)");
$sql->bindParam(':login', $field1, PDO::PARAM_STR);
$sql->bindParam(':password', hash_password(), PDO::PARAM_STR);
$sql->bindParam(':first_name', $field3, PDO::PARAM_STR);
$sql->bindParam(':last_name', $field4, PDO::PARAM_STR);
$sql->bindParam(':email', $field5, PDO::PARAM_STR);
$sql->bindParam(':birth_date', $field6, PDO::PARAM_STR);
$sql->bindParam(':gender', $field7, PDO::PARAM_STR);
$sql->bindParam(':age', $age10, PDO::PARAM_INT);
$sql->bindParam(':number_phone', $field8, PDO::PARAM_INT);
$sql->bindParam(':avatar', $field10, PDO::PARAM_STR);
$sql->execute();
}
}