Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. public function _hash_string($str){
  2. $hashed_string = password_hash($str, PASSWORD_BCRYPT);
  3. return $hashed_string;
  4. }
  5.  
  6. public function _verify_hash($text, $hashed_string){
  7. $result = password_verify($text, $hashed_string);
  8. return result; //TRUE OR FALSE
  9. }
  10.  
  11. public function index()
  12. {
  13. if($this->input->post('newuser') == 1)
  14. {
  15. $user = new Users_model();
  16. $user->username = $this->input->post('username');
  17. $user->email = $this->input->post('email');
  18. $pass= $this->input->post('password');
  19. $hashed_pass = $this ->_hash_string($pass);
  20. $user->password = $hashed_pass;
  21. $user->account_status = 1;
  22. $user->user_role = $this->input->post('user_role');
  23. $id = $this->usermodel->insert($user);
  24. }else{
  25. $this->load->view('signup-page');
  26. }
  27.  
  28. public function index()
  29. {
  30. if($this->input->post('login') == 1)
  31. {
  32. $user = new Users_model();
  33. $user->email = $this->input->post('email');
  34. $user->password = $this->input->post('password');
  35. $user->user_role = $this->input->post('user_role');
  36. $results = $this->usermodel->login($user);
  37. if(count($results) > 0)
  38. {
  39. foreach($results as $row)
  40. {
  41. $session_array = array(
  42. "id" => $row['id'],
  43. "username" => $row['username'],
  44. "email" => $row['email'],
  45. "password" => $row['password'],
  46. "account_status" => $row['account_status'],
  47. "user_role" => $row['user_role']
  48. );
  49. $this->session->set_userdata($session_array);
  50. $url = base_url() . "home?login=success";
  51. redirect($url, "refresh");
  52. }
  53. }else{
  54. $url = base_url() . "login?login=failed";
  55. redirect($url, "refresh");
  56. }
  57. }else{
  58. $this->load->view('login-page');
  59. }
  60. }
  61.  
  62. function login($user){
  63. $conditions = array(
  64. "email" => $user->email,
  65. "password" => $user->password,
  66. "user_role" => $user->user_role,
  67. "account_status" => 1,
  68. );
  69. $this->db->select('*');
  70. $this->db->from('users');
  71. $this->db->where($conditions);
  72. $rs= $this->db->get();
  73. return $rs->result_array();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement