4
//=======================================
5
// This 'small' PHP script updates
6
// the information for the administrator
7
//=======================================
9
// Include the file containing DB credentials
10
require_once '/var/www/config.inc.php';
12
// We should have received 4 command line arguments
15
echo "Usage: {$argv[0]} name email password\n";
23
// Connect to the database server
24
$sql = new mysqli($THINKUP_CFG['db_host'],
25
$THINKUP_CFG['db_user'],
26
$THINKUP_CFG['db_password'],
27
$THINKUP_CFG['db_name']);
29
// Make sure the connection is valid
30
if($sql->connect_error)
32
echo "MySQL connection error: {$sql->connect_error}\n";
36
// Check if the user exists (NOTE: this is not foolproof there are no
37
// provisions for changing your email address.)
38
if(!($statement = $sql->prepare('SELECT id FROM tu_owners WHERE email = ?')))
40
echo "MySQL error: {$sql->error}\n";
44
$statement->bind_param('s', $email);
45
$statement->bind_result($id);
47
if($statement->execute() === FALSE)
49
echo "MySQL error: {$sql->error}\n";
53
$user_exists = $statement->fetch();
58
// Okay, we're updating the user with the specified email address
59
if(!($statement = $sql->prepare('UPDATE tu_owners SET full_name = ?, pwd = ?, pwd_salt = ? WHERE id = ?')))
61
echo "MySQL error: {$sql->error}\n";
65
// Generate a salt and hash the password
66
$salt = hash('sha256', rand() . $email);
67
$hash = hash('sha256', $pass . $salt);
69
$statement->bind_param('sssi', $name, $hash, $salt, $id);
72
if($statement->execute() === FALSE)
74
echo "MySQL error: {$sql->error}\n";
81
if(!($statement = $sql->prepare('INSERT INTO tu_owners (full_name, pwd, pwd_salt, email, joined, is_activated, is_admin, last_login) VALUES (?, ?, ?, ?, NOW(), 1, 1, NOW())')))
83
echo "MySQL error: {$sql->error}\n";
87
// Generate a salt and hash the password
88
$salt = hash('sha256', rand() . $email);
89
$hash = hash('sha256', $pass . $salt);
91
// Bind the parameters
92
$statement->bind_param('ssss', $name, $hash, $salt, $email);
95
if($statement->execute() === FALSE)
97
echo "MySQL error: {$sql->error}\n";