Dette logind system er skrevet i php med mysqli. Men vil gerne have at vide at det er sikkert. Og hvordan kan jeg bruge denne kode i en function :
index.php
- $stmt = $mysqli->prepare("SELECT * FROM `users` WHERE username='$username' AND password='$password' AND SPS='$SPS'");
- $stmt->bind_param('t', $_GET['username']);
- $stmt->execute();
- $result = $stmt->get_result();
- $row = $result->fetch_assoc();
- if ($row = 1) { }
Så den fx kunne bruges sådan
- if (checkuserexists = 1) {
- echo 'User exists';
- } else {
- echo 'No user found.';
- }
EDIT :
Fulde kode
- <?php
-
- if ($sid && $sbrugernavn) {
- echo 'Welcome ' . $sbrugernavn;
- } else {
- if ($_POST) {
- $username = htmlentities($_POST['username']);
- $password = $_POST['Password'];
- $SPS = $_POST['SPS'];
-
- if ($username && $password) {
- $password = md5($password . $username . $salt);
- $password = sha1($password);
- $SPS = md5('s334sytgehnfyt3hrfen4' . $salt . 'feshnDE45r' . $password . $SPS);
- $SPS = sha1($SPS);
- $stmt = $mysqli->prepare("SELECT * FROM `users` WHERE username='$username' AND password='$password' AND SPS='$SPS'");
- $stmt->bind_param('t', $_GET['username']);
- $stmt->execute();
- $result = $stmt->get_result();
- $row = $result->fetch_assoc();
- if ($row = 1) {
-
- $user_info = $mysqli->query("SELECT * FROM `users` WHERE username='$username'");
- while ($row = $user_info->fetch_assoc()) {
- echo $row['id'];
- $_SESSION['id'] = $row['id'];
- $_SESSION['username'] = $username;
-
- header('Location: index.php');
- }
- } else {
- echo 'Wrong username or password.';
- }
- } else {
- echo 'All fields is requried!.';
- }
- }
- ?>
- <form action="index.php" method="post">
- <label for="username">Username *</label> <br />
- <input type="text" name="username" id="username" placeholder="Write your username"/> <br />
-
- <label for="Password">Password *</label><br />
- <input type="password" name="Password" id="Password" placeholder="Write your Password"/><br />
-
- <label for="SPS">Your speical password (can be anything)*</label><br />
- <input type="password" name="SPS" id="SPS" placeholder="Write your Speical Password"/><br /> <br />
-
- <input type="submit" value="Login" />
-
- </form>
- <?php
- }
- ?>
Er det et sikker login ellers må i godt komme med nogen eksempler.
Indlæg senest redigeret d. 18.11.2013 18:18 af Bruger #17607