I have a task to make a login system using php, specifically one that hashes passwords into a .txt file (which is not the way you want) I have tried this but can't figure out how to even start . I was told to use the function file() to create an array. Any kind of help would be greatly appreciated
Currently we have this
<!DOCTYPE html> <html lang="en"> <body> <form action="test.php" method="post"> <span>Username</span> <input type="text" name="Username" id="Login-Input-Username" required><br> <span>Password</span> <input type="password" name="Password" id="Login-Input-Password" required> <button type="submit" name="Submit-Button" value="submit" id="Login- Button">Sign In</button> </form> <?php if(isset($_POST['Submit-Button'])) { $username = $_POST['Username']; $password = $_POST['Password']; $hash = password_hash($password, PASSWORD_DEFAULT); $fileRows = file("accounts.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); }?>
P粉4182142792024-04-03 10:54:03
I don't really know why you want to store the data in a file, but you can rewrite your PHP code like below
$username, 'password' => $hash, ]; $fileRows = file_put_contents('accounts.txt', json_encode($data).PHP_EOL , FILE_APPEND | LOCK_EX); }?>