Advertisement
Guest User

Untitled

a guest
May 27th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.98 KB | None | 0 0
  1. <?php
  2. require('config.php');
  3.     function doesUsernameExist($name){
  4.         $exit = FALSE;
  5.         $result = @mssql_query("SELECT * FROM ACCOUNT_TBL WHERE account='$name'");
  6.         if (mssql_num_rows($result) != 0){
  7.             $exit = TRUE;
  8.         }
  9.         return $exit;
  10.     }
  11.  
  12.     if(isset($_POST['submit'])){
  13.         $user = preg_replace ("[^A-Za-z0-9]", "", $_POST['username']);
  14.         $pass = preg_replace ("[^A-Za-z0-9]", "", $_POST['password']);
  15.         if($_POST['username'] == ""){
  16.             echo 'Please enter a username.';
  17.         }
  18.         else if($_POST['password'] == ""){
  19.             echo 'Please enter a password.';
  20.         }
  21.         else if ((strlen($_POST['username']) > 16) || (strlen($_POST['username']) < 3)){
  22.             echo 'The username should be 3 to 16 characters.';
  23.         }
  24.         else if ((strlen($_POST['password']) > 16) || (strlen($_POST['password']) < 3)){
  25.             echo 'The password should be 3 to 16 characters.';
  26.         }
  27.         else if($_POST['username'] != $user){
  28.             echo 'Please choose another username.';
  29.         }
  30.         else if($_POST['password'] != $pass){
  31.             echo 'Please choose another password.';
  32.         }
  33.         else {
  34.             $pass = md5('serus' . $pass);
  35.             if(!doesUsernameExist($user)){
  36.                 $stmt = mssql_init('usp_CreateAccount', $link);
  37.                 mssql_bind($stmt, '@account', $user, SQLVARCHAR, false, false, 15);
  38.                 mssql_bind($stmt, '@password', $pass, SQLVARCHAR, false, false, 36);
  39.                 mssql_execute($stmt) or die ("Something is wrong on the execution");
  40.                 mssql_free_statement($stmt);
  41.                 echo 'Congratulations! You have successfully registered an account.';
  42.             }
  43.             else {
  44.                 echo 'Username already exist.';
  45.             }
  46.         }
  47.         mssql_close();
  48.     }
  49.    
  50.     echo '<form action="#" method="post">';
  51.     echo 'Username: <input type="text" name="username" /><br />';
  52.     echo 'Password: <input type="password" name="password" /><br />';
  53.     echo '<input type="submit" name="submit" value="Register" />';
  54.     echo '</form>';
  55.  
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement