Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $user_username = $_POST['userName'];
- $user_password = $_POST['passWord'];
- $hashed_password = password_hash($user_password, PASSWORD_DEFAULT);
- if(isset($_POST['submit_button'])) {
- $accountInfo = $user_username . ":" . $hashed_password . "\n";
- $filepath = fopen('useraccounts.txt', 'a+');
- $file = "useraccounts.txt";
- if (file_exists($file)) {
- $content = file_get_contents($file);
- $content = explode("\n", $content);
- $users = array();
- foreach ($content as $value) {
- $user = explode(':', $value);
- $users[$user[0]] = $user[1];
- }
- print_r($users);
- if(array_key_exists($user_username, $users)){
- echo "username is alrdy taken";
- }
- if (isset($users[$_POST['userName']])) {
- echo "that name is alrdy taken";
- }
- elseif (empty($user_username) || empty($user_password)) {
- echo "Fill in both PASSWORD and USERNAME";
- }
- else {
- fwrite($filepath, $accountInfo);
- echo "saved";
- }
- fclose($filepath);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement