Guest User

Untitled

a guest
Oct 23rd, 2017
3,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. <?php
  2. function createNewUser($email, $password) {
  3.  
  4. if (isValidEmail($email)) {
  5.  
  6. if (isValidPassword($password)) {
  7.  
  8. $db = getDB();
  9. $stmt = $db->prepare("INSERT INTO users SET email = :email, password = :password, created = now()");
  10. $hashedPassword = hash('sha1', $password);
  11. $binds = array(
  12. ":email" => $email,
  13. ":password" => $hashedPassword
  14. );
  15. if ($stmt->execute($binds) && $stmt->rowCount() > 0) {
  16. return true;
  17. }
  18. }
  19. }
  20. return false;
  21. }
  22.  
  23. function isValidEmail($value) {
  24. if (empty($value)) {
  25. return false;
  26. }
  27. if (filter_var($value, FILTER_VALIDATE_EMAIL) == false) {
  28. return false;
  29. }
  30. return true;
  31. }
  32.  
  33. function isValidPassword($value) {
  34. if (empty($value)) {
  35. return false;
  36. }
  37.  
  38. if (preg_match("/^[a-zA-Z0-9]+$/", $value) == false) {
  39. return false;
  40. }
  41. return true;
  42. }
  43.  
  44. function existingEmail($emailToCheck, $keyToCheck, $dbSheetToCheck){
  45. $db = getDB();
  46.  
  47. //get list of sites to compare with site entered
  48. $stmt = $db->prepare("SELECT * FROM $dbSheetToCheck");
  49. $contentsOfDB = array();
  50. $newArrayToCheck = array();
  51.  
  52. if ($stmt->execute() && $stmt->rowCount() > 0)
  53. {
  54. $contentsOfDB = $stmt->fetchAll(PDO::FETCH_ASSOC);
  55. }
  56. // //print entire array with keys for testing purposes
  57. // $keys = array_keys($contentsOfDB);
  58. // for($i = 0; $i < count($contentsOfDB); $i++)
  59. // {
  60. // echo $keys[$i] . "{<br>";
  61. // foreach($contentsOfDB[$keys[$i]] as $key => $value)
  62. // {
  63. // echo $key . " : " . $value . "<br>";
  64. // }
  65. // echo "}<br>";
  66. // }
  67. for($i = 0; $i < count($contentsOfDB); $i++)
  68. {
  69. $newArrayToCheck[$i] = $contentsOfDB[$i][$keyToCheck];
  70. }
  71.  
  72. if (in_array($emailToCheck, $newArrayToCheck)== false)
  73. {
  74. return false;
  75. }
  76. else
  77. {
  78. return true;
  79. }
  80. }
Add Comment
Please, Sign In to add comment