Guest User

Untitled

a guest
Nov 27th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. <?php
  2.  
  3. function hash_password($password) {
  4. return hash('sha256', $password);
  5. }
  6.  
  7. function check_password($hash, $password) {
  8. return $hash === hash_password($password);
  9. }
  10.  
  11. function authenticate($email, $password) {
  12. $user = R::findOne('user', ' email=? ', array($email));
  13. if ($user === null) return false;
  14. return check_password($user->encrypted_password, $passwod);
  15. }
  16.  
  17. function save_user($name, $email, $password) {
  18. $user = R::dispense('user');
  19. $user->name = $name;
  20. $user->email = $email;
  21. $user->encrypted_password = hash_password($password);
  22. $id = $::store($user);
  23. if ($id === null) return null;
  24. return $user;
  25. }
Add Comment
Please, Sign In to add comment