Guest User

Untitled

a guest
Feb 11th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1.  <?
  2.  
  3.     // require common code
  4.     require_once("includes/common.php");
  5.    
  6.     // check if username or password is blank
  7.     if ($_POST["username"]|$_POST["password"] == "")
  8.     {  
  9.         // apologize
  10.         apologize("Type username/password!");
  11.     }
  12.    
  13.     // check if password is equal to password2
  14.     if ($_POST["password"] != $_POST["password2"])
  15.     {  
  16.         // apologize
  17.         apologize("The passwords are not equal!");              
  18.     }
  19.    
  20.    
  21.     // escape username to avoid SQL injection attacks
  22.     $username = mysql_real_escape_string($_POST["username"]);
  23.      
  24.     // encrypt the passwords and store it as hash value
  25.     $hash = crypt($_POST["password"]);
  26.    
  27.     mysql_query('INSERT INTO users (username, hash, cash) VALUES (' . $username . ', ' . $hash . ', 10000.00)')or die(mysql_error());
  28.    
  29.     // look in the database if username already exists
  30.     if (mysql_query($sql) != UNIQUE)
  31.     {
  32.         return 0;  
  33.         apologize("Username already exists!");
  34.     }
  35.    
  36.     // remember that user's now logged in by caching user's ID in session
  37.     $_SESSION["id"] = $row["id"];
  38.    
  39.     // redirect to portfolio
  40.     redirect("index.php");
  41.    
  42.     // else report error
  43.     apologize("Invalid username and/or password!");
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment