mysql - Password hash being changed on database entry php -
mysql - Password hash being changed on database entry php -
using password_hash() , hash password , store in db, not pass password_verify. tried testing functions out running word through them outside of database, worked fine. and, if hash word, manually set in database, works fine in login. but, when come in hash database via code/sql...something apparently happening hash @ point , making unusable (from can tell). can't figure out what. checked table..that seems fine, varchar(255) utf8_bin. using codeigniter framework. codeigniter escapes it's inserts unless set below , utilize false - did not work.
function register($data){ $this->db->set($data, false); $this->db->set('word_of_passing', $data['word_of_passing'], false); $this->db->insert('cred'); }
this did not work -
function register($data){ $this->db->query('insert cred (user_name, word_of_passing) values ("'.$data['user_name'].'", "'.$data['word_of_passing'].'")'); }
this did not work -
function register($data){ $this->db->insert('cred', $data); }
and tried go outside codeigniter this..did not work -
$servername = "localhost"; $username = "root"; $password = ""; $dbname = "moviedb"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "insert cred (user_name, word_of_passing) values ('".$data['user_name']."', '".$data['word_of_passing']."')"; if ($conn->query($sql) === true) { echo "new record created successfully"; } else { echo "error: " . $sql . "<br>" . $conn->error; } $conn->close();
my controller -
public function check_pw(){ //password , username post $data = $this->input->post('username'); $password = $this->input->post('password'); //pass username model retrieve stored hash $this->load->model('lindsdata'); $return_data = $this->lindsdata->password($data); //$pw indeed getting stored hash, not passing $pw = password_verify($password, $return_data[0]['word_of_passing']); if ($pw == 1) { $this->session->set_userdata(array("logged_in" => "true", "user_id" => $return_data[0]['user_id'] )); redirect('/update/user', 'location'); }else{ $error['the_error'] = 'your credentials wrong'; } }
all can think has setting in database or something? stumped.
if insert problem in database suggest add together model function controller set model name , function
class lindsdata extends ci_modle{ public function password(){ $data = array( 'user_name' => $this->input->post('username'), 'word_of_passing' => $this->input->post('password'), ); $query = $this->db->insert('cred',$data); if($query) { homecoming true; } else { homecoming false; } } }
get in controller like
$this->load->model('lindsdata'); $return_data = $this->lindsdata->password();
php mysql database codeigniter hash
Comments
Post a Comment