Advertisement
Guest User

asdasd

a guest
Mar 4th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. $user_username = $_POST['userName'];
  2. $user_password = $_POST['passWord'];
  3.  
  4. $hashed_password = password_hash($user_password, PASSWORD_DEFAULT);
  5.  
  6.   if(isset($_POST['submit_button'])) {
  7.       $accountInfo = $user_username . ":" . $hashed_password . "\n";
  8.       $filepath = fopen('useraccounts.txt', 'a+');
  9.       $file = "useraccounts.txt";
  10.  
  11.       if (file_exists($file)) {
  12.           $content = file_get_contents($file);
  13.           $content = explode("\n", $content);
  14.           $users = array();
  15.  
  16.           foreach ($content as $value) {
  17.               $user = explode(':', $value);
  18.               $users[$user[0]] = $user[1];
  19.           }
  20.           print_r($users);
  21.  
  22.           if(array_key_exists($user_username, $users)){
  23.               echo "username is alrdy taken";
  24.           }
  25.  
  26.           if (isset($users[$_POST['userName']])) {
  27.               echo "that name is alrdy taken";
  28.           }
  29.           elseif (empty($user_username) || empty($user_password)) {
  30.               echo "Fill in both PASSWORD and USERNAME";
  31.           }
  32.           else {
  33.               fwrite($filepath, $accountInfo);
  34.               echo "saved";
  35.           }
  36.           fclose($filepath);
  37.       }
  38.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement