Welcome Guest, Not a member yet? Register   Sign In
hashing password and decrypting(need hlp)
#1

i have hashed my password but i can't decrypt it.what is the best way to solve the situation.can someone help me solve it.
this is my insert model

public function insert_client($codeDigits)
   {
     $hash = $this->hash($_POST['Password']);
       $response = $this->taken_email($_POST['Email']);
       if($response){
           $returned = false;
       }else{
               $this->FirstName    = $_POST['FirstName']; // please read the below note
               $this->LastName    = $_POST['LastName'];
               $this->Email     = $_POST['Email'];  
               $this->Role_Id     = 2;  
               $this->Password = $hash;
               $this->PhoneNo    = $_POST['PhoneNo'];
               $this->confirmCode    = $codeDigits;
               $this->db->insert('users', $this);

         $returned = true;
           }
           
           return $returned;
       }


this is my password harsh model
public function hash($password)
  {
      $hash = password_hash($password,PASSWORD_DEFAULT);
      return $hash;
  }

  //verify password
  public function verifyHash($password,$vpassword)
  {
      if(password_verify($password,$vpassword))
      {
          return TRUE;
      }
      else{
          return FALSE;
      }
  }


this is my login model
public function login_model($email,$password)
  {
   
      $this->db->select('*');
      $this->db->from('users');
      $this->db->where(' Email',$email);
      $this->db->where('Password',$password);
      $this->db->where('Role_Id !=',1);
      $query = $this->db->get();

      if($query->num_rows() > 0)
      {
          $results = $query->row();
          // storing the results in the variable $data

          foreach($results as $data)
          {
              if($this->verifyHash($this->$password,$data->password == TRUE))
              {
                  $dat = array(
               'id_user' => $data->id_User,
               'FirstName' => $data->FirstName,
               'LastName' => $data->LastName,
               'Phonenumber' => $data->PhoneNo,                  
               'Email' => $data->Email,
               'role' => $data->Role_Id,
               'imageUrl' => $data->imageUrl,
               'category_id' => $data->category_id,
               'IdType' => $data->IdType,
               'IdNumber' => $data->IdNumber,
               'DOB' => $data->DOB,
               'confirmCode' => $data->confirmCode,
               'confirmed' => $data->confirmed,
               'Points'=> $data->Points                  
                  );
               }
           
              $this->session->set_userdata($dat);
             return true;
           }        
      }
      else{
          return false;
       }
     
  }


please someone should help me to make the login work
Reply
#2

The php password_hash uses bcrypt encryption so you cannot decrypt.

You can make your own method and create a new password then edit your database user and change it to the new one.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Also, why would you decrypt any passwords?
There was enough media coverage recently about data breeches and companies storing passwords in easily recoverable format let alone as free-text
Reply
#4

what would be the best solution to do this?kindly send me a code if you one
Reply
#5

@InsiteFX and @qury
He wants to verify it and login a person. Not decrypt the password; It's just a bad choice of words.

PHP Code:
public function login_model($email,$password)
  {
   
      
$this->db->select('*');
      
$this->db->from('users');
      
$this->db->where('Email',$email);
      
$this->db->where('Role_Id !=',1);
      
$query $this->db->get();

      if(
$query->num_rows() === 1)
      {
          
// storing the results in the variable $data
          
$data $query->row(); 

            if(
$this->verifyHash($password,$data->password) === TRUE)
            {
                
$dat = array(
                   
'id_user' => $data->id_User,
                   
'FirstName' => $data->FirstName,
                   
'LastName' => $data->LastName,
                   
'Phonenumber' => $data->PhoneNo,                  
                   
'Email' => $data->Email,
                   
'role' => $data->Role_Id,
                   
'imageUrl' => $data->imageUrl,
                   
'category_id' => $data->category_id,
                   
'IdType' => $data->IdType,
                   
'IdNumber' => $data->IdNumber,
                   
'DOB' => $data->DOB,
                   
'confirmCode' => $data->confirmCode,
                   
'confirmed' => $data->confirmed,
                   
'Points'=> $data->Points                  
                
);
            }
           
            
$this->session->set_userdata($dat); 
            return 
true;     
      }
      else{
          return 
false;
       }
      
  } 
Reply
#6

(06-06-2018, 12:54 PM)it still didn\t work out.i just don't know what i'm doing wrong here. Wrote: @InsiteFX and @qury
He wants to verify it and login a person. Not decrypt the password; It's just a bad choice of words.

PHP Code:
public function login_model($email,$password)
 
 {
 
  
      $this
->db->select('*');
 
     $this->db->from('users');
 
     $this->db->where('Email',$email);
 
     $this->db->where('Role_Id !=',1);
 
     $query $this->db->get();

 
     if($query->num_rows() === 1)
 
     {
 
         // storing the results in the variable $data
 
         $data $query->row(); 

 
           if($this->verifyHash($password,$data->password) === TRUE)
 
           {
 
               $dat = array(
                 
  'id_user' => $data->id_User,
                 
  'FirstName' => $data->FirstName,
                 
  'LastName' => $data->LastName,
                 
  'Phonenumber' => $data->PhoneNo                 
                   
'Email' => $data->Email,
                 
  'role' => $data->Role_Id,
                 
  'imageUrl' => $data->imageUrl,
                 
  'category_id' => $data->category_id,
                 
  'IdType' => $data->IdType,
                 
  'IdNumber' => $data->IdNumber,
                 
  'DOB' => $data->DOB,
                 
  'confirmCode' => $data->confirmCode,
                 
  'confirmed' => $data->confirmed,
                 
  'Points'=> $data->Points                  
                
);
 
           }
 
          
            $this
->session->set_userdata($dat); 
 
           return true    
      
}
 
     else{
 
         return false;
 
      }
 
     
  

Reply
#7

Okey, then you need to check individual function one by one and supply us with an error message. You should receive one.

Make an empty PHP-file (without Codeigniter) and try to verify the password by passing in strings.
Reply
#8

(06-07-2018, 03:50 AM)Ok I\ll do that Wrote: Okey, then you need to check individual function one by one and supply us with an error message. You should receive one.

Make an empty PHP-file (without Codeigniter) and try to verify the password by passing in strings.
Reply
#9

Did you check your database table to see if the values were inserted into it?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

(06-07-2018, 09:27 AM)I nsiteFX Wrote: Did you check your database table to see if the values were inserted into it?

Yes,i checked and password was hashed
Reply




Theme © iAndrew 2016 - Forum software by © MyBB