-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupUsers.php
More file actions
51 lines (43 loc) · 1.27 KB
/
Copy pathsetupUsers.php
File metadata and controls
51 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Created by PhpStorm.
* @author Zachary Hughes <zhughes3@gmail.com>
* Date: 3/16/2016
* Time: 10:55 AM
* Description: Practicing storing usernames and passwords (using hashing and salting for security).
*/
require_once 'login.php';
$connection;
function addUser($conn, $fn, $ln, $un, $pw) {
global $iniSalt, $endSalt;
$iniSalt = "xb&z*";
$endSalt = "nb!@";
$token = hash('ripemd128', "$iniSalt$pw$endSalt");
$query = "INSERT INTO users VALUES('$fn', '$ln', '$un', '$token')";
$result = $conn->query($query);
if (!$result) {
die($conn->error);
} else {
echo "Row added to table users " .
"firstname = '$fn' " .
"lastname = '$ln' " .
"username = '$un'<br>";
}
}
$connection = new mysqli($db_host, $user, $pass, $db);
if ($connection->connect_error) {
die($connection->connect_error);
}
$query = "CREATE TABLE IF NOT EXISTS users (
firstname VARCHAR(32) NOT NULL,
lastname VARCHAR(32) NOT NULL,
username VARCHAR(32) NOT NULL UNIQUE,
password VARCHAR(256) NOT NULL
)";
$result = $connection->query($query);
if (!$result) {
die($connection->error);
}
addUser($connection, 'Bill', 'Murray', 'bmurray', 'mysecret');
addUser($connection, 'Sarah', 'Robertson', 'srob', 'virgin3');
?>