Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. require_once('connect.php');
  2. {
  3. $uname = strip_tags($_POST['username']);
  4. $upass = $_POST['password'];
  5.  
  6. if ( empty($uname) ) {
  7. $errors[] = "Username can't be empty";
  8. } elseif ( strlen($uname) > 64 or strlen($uname) < 5 ) {
  9. $errors[] = "Username must be longer than 5 characters and shorter than 64";
  10. } elseif( empty($upass) ) {
  11. $errors[] = "Please enter a password";
  12. } elseif ( strlen($upass) < 6 ) {
  13. $errors[] = "Password has a minimum length of 6 characters";
  14. } else {
  15.  
  16. $query = "SELECT username, pass FROM users WHERE username=?";
  17. $stmt = mysqli_prepare($dbconnect, $query);
  18.  
  19. mysqli_stmt_bind_param($stmt, "s", $uname);
  20. mysqli_stmt_execute($stmt);
  21. mysqli_stmt_store_result($stmt);
  22.  
  23. if (mysqli_stmt_num_rows($stmt) == 1) {
  24. mysqli_stmt_bind_result($stmt, $db_uname, $db_pass);
  25. mysqli_stmt_fetch($stmt);
  26.  
  27. if (password_verify($upass, $db_pass)) {
  28. echo "Success";
  29. } else {
  30. echo "Wrong username or password";
  31. }
  32. } else {
  33. echo "No user found";
  34. }
  35. }
  36.  
  37. if(!empty($errors)) {
  38. foreach( $errors as $error ) {
  39. echo $error;
  40. }
  41. }
  42.  
  43. $hashed_pass = password_hash($upass1, PASSWORD_DEFAULT);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement