I have a login code I want to use a password hash on, but when I tried to login, the progress bar will roll for eternity without logging in. below are my password hash creation, and login code. Anyone with solution on how i can resolve the issue is highly welcome.
hash creation code
if(empty($_POST['password']))
unset($_POST['password']);
else
$_POST['password'] = password_hash($_POST['password'], PASSWORD_DEFAULT);
extract($_POST);
$data = '';
foreach($_POST as $k => $v){
if(!in_array($k,array('id'))){
if(!empty($data)) $data .=" , ";
$data .= " {$k} = '{$v}' ";
}
}
if(empty($id)){
$qry = $this->conn->query("INSERT INTO users set {$data}");
if($qry){
$id=$this->conn->insert_id;
$this->settings->set_flashdata('success','User Details successfully saved.');
foreach($_POST as $k => $v){
if($k != 'id'){
if(!empty($data)) $data .=" , ";
if($this->settings->userdata('id') == $id)
$this->settings->set_userdata($k,$v);
}
}
Login code
public function login(){
extract($_POST);
$stmt = $this->conn->prepare("SELECT * from users where username = ? and password = ? ");
$password = password_verify($password, $hashed_password);
$stmt->bind_param('ss',$username,$password);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows > 0){
foreach($result->fetch_array() as $k => $v){
if(!is_numeric($k) && $k != 'password'){
$this->settings->set_userdata($k,$v);
}
}
$this->settings->set_userdata('login_type',1);
return json_encode(array('status'=>'success'));
}else{
return json_encode(array('status'=>'incorrect','last_qry'=>"SELECT * from users where username = '$username' and password = md5('$password') "));
}
}
public function logout(){
if($this->settings->sess_des()){
redirect('admin/login.php');
}
}