php - Codeigniter decode not working -


i making little login system using php inside of codeigniter framework. using encryption class encode password, store in database. on login, finds encrypted password using username, matches against password entered. passwords getting encoded during registration. , in below code, have been able print out encoded password database, fails out whenever run through decode. no error message, nothing.

public function check_pw(){     //post username , password database     $data['username'] = $this->input->post('username');     $data['password'] = $this->input->post('password');     $this->load->model('lindsdata');     //encoded password returned database - working     $return_data = $this->lindsdata->password($data);     //$return_data = $this->encrypt->decode($return_data);       //print_r shows $return_data hold encrypted password     //but when uncomment line decode in it, $return_data print_rs nothing.      print_r($return_data);     if ($return_data == $data['password']) {         redirect('/update/user', 'location');     }     if($return_data !== $data['password']){         //at point, $return_data of course still has nothing         print_r($return_data);         //print_r below entered password user..that shows up.         print_r($data['password']);         $error['the_error'] = 'your credentials wrong';     }else{         $error['the_error'] = '';     } } 

i tried below make sure things being encoded properly...this returned "test" expected.

 $a = "test";  $test = $this->encrypt->encode($a);   $test = $this->encrypt->decode($test);  print_r($test); 

to further confuse me...i manually encoded password (like in code above) , had put result in database user (i had not set registration form yet, did had user work with)...that 1 works fine reason. none of other encoded user passwords working. don't why failing out during decode. database set varchar(255). , getting encoded password when run through decode...but nothing. no error message or , stumped. advance. ...and did not post model because don't think relevant since indeed returning encoded password checking should.

edit - doesn't make sense $return_data printing hash db , $password returning proper password $pw returning nothing. ...could sql database somehow corrupting/editing hash? should work can tell.

    $data['username'] = $this->input->post('username');     $password = $this->input->post('password');     $this->load->model('lindsdata');     $return_data = $this->lindsdata->password($data);     print_r($return_data);     print_r($password);     $pw = password_verify($password, $return_data);     print_r($pw); 

edit - input database quite simple... see no reason having issue. ...still failing on either decode or password_verify. still no idea problem. simple mysql database...

public function register_submit(){     $data['user_name'] = $this->input->post('user_name');     $pwd = $this->input->post('password');     $data['password'] =  password_hash($pwd, password_default);     $this->load->model('lindsdata');     $this->lindsdata->register($data);       }  function register($data){     $this->db->insert('cred', $data); } 

it against security practices directly store password in database, if encrypted. if get's access server can take both code , snapshot of database , find out passwords of users registered on site. best practice regarding passwords save hash of password (preferably sha256 or stronger), , compare hash of password user enters in login form 1 stored in database. or, better, can use php built in password hashing support (http://php.net/manual/en/ref.password.php).

and indirectly, hashing password solve problem :)


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -