Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" type="text/css" href="footer2.css">
- <title> Webbutveckling 2</title>
- </head>
- <body>
- <h1> Uppgift 2a - Skapa en användare och logga sedan in! </h1>
- <?php
- //nedan inkluderar/bifogar jag sidan "footer.php".
- include 'footer2.php';
- echo "<br>";
- session_start();
- function createUser(){
- $user_username = $_POST['userName'];
- $user_password = $_POST['passWord'];
- $password_hashed = password_hash($user_password, PASSWORD_DEFAULT);
- $user_usernameLower = strtolower($user_username);
- $accountInfo = $user_usernameLower . ":" . $password_hashed . "\n";
- $filepath = fopen('useraccounts.txt', 'a+');
- $file = "useraccounts.txt";
- if (isset($_POST['submit_button'])) {
- 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];
- }
- if (isset($users[$_POST['userName']])) {
- echo "that username is already taken";
- } elseif (empty($user_username) || empty($user_password)) {
- echo "Please, Fill in both password and username";
- } else {
- fwrite($filepath, $accountInfo);
- echo "Account created! ";
- }
- fclose($filepath);
- }
- }
- }
- createUser();
- ?>
- <br>
- <form action="" method="post">
- <label> Skapa användare nedan </label><br>
- <label>Username: </label><input type="text" name="userName" placeholder="Username">
- <br>
- <label>Password: </label> <input type="password" name="passWord" placeholder="Password">
- <br><br>
- <input type="submit" name="submit_button" value="createUser">
- </form>
- <br>
- <br>
- <form action="index.php" method="post">
- <label> Logga in nedan</label><br>
- <label>Username: </label><input type="text" name="userName" placeholder="Username">
- <br>
- <label>Password: </label> <input type="password" name="password" placeholder="Password">
- <br><br>
- <input type="submit" name="submit_button1" value="Login">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement