Create a basic PHP login system: a step-by-step guide
P粉139351297
P粉139351297 2024-04-02 11:54:37
0
1
519

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粉139351297
P粉139351297

reply all(1)
P粉418214279

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);    
    }?>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!