Heim  >  Fragen und Antworten  >  Hauptteil

Erstellen Sie ein einfaches PHP-Anmeldesystem: eine Schritt-für-Schritt-Anleitung

Ich habe die Aufgabe, ein Anmeldesystem mit PHP zu erstellen, insbesondere eines, das Passwörter in eine TXT-Datei hasht (nicht so, wie Sie es möchten). Ich habe es versucht, weiß aber nicht, wie ich überhaupt anfangen soll. Mir wurde gesagt, ich solle die Funktion file() verwenden, um ein Array zu erstellen. Jede Art von Hilfe wäre sehr dankbar

Aktuell haben wir das

<!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粉139351297P粉139351297173 Tage vor397

Antworte allen(1)Ich werde antworten

  • P粉418214279

    P粉4182142792024-04-03 10:54:03

    我真的不知道为什么你想将数据存储在文件中,但你可以重写你的 PHP 代码,如下所示

     $username,
            'password' => $hash,
        ];
    
        $fileRows = file_put_contents('accounts.txt', json_encode($data).PHP_EOL , FILE_APPEND | LOCK_EX);    
        }?>

    Antwort
    0
  • StornierenAntwort