Forum Moderators: coopster
$mysqli = new mysqli("localhost", "xxx", "xxx", "xxx");
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
// Encrypt
if ($stmt = $mysqli->prepare("SELECT * FROM `clients` WHERE `username` = ? AND `password` = ? LIMIT 1")) {
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows == 1) {
if ($stmt = $mysqli->prepare("SELECT `userid` FROM `clients` WHERE `username` = '$username'")) {
$stmt->execute();
$stmt->bind_result($user_id);
while ($stmt->fetch()) {
echo $user_id;
}
$_SESSION['userid'] = $user_id;
$_SESSION['username'] = $username;
$sess_id = session_id();
$_SESSION['sessid'] = $sess_id;
header("Location: nextpage.php");
$stmt->close();
$mysqli->close();
// Connect to db
// Other checks like is form filled out, valid email etc
$sess_id = session_id();
$_SESSION['sessid'] = $sess_id;
$salt = uniqid(mt_rand(), true);
$hashed_pw = sha1($salt . $password);
if ($stmt = $mysqli->prepare("INSERT INTO clients
(status, username, clientusername, salt, password, type, sessid, firstname, lastname, companyname)
values ('A', ?, ?, ?, ?, 'superuser', ?, ?, ?, ?)")) {
$stmt->bind_param('ssssssss', $email, $email, $salt, $hashed_pw, $sess_id, $first_name, $last_name, $company_name );
$stmt->execute();
header("Location: next_page.php");
$stmt->close();
$mysqli->close();
// Connect to db
// Other checks like is form filled out, not empty etc
if ($stmt = $mysqli->prepare("SELECT userid, salt, password FROM `clients` WHERE `username` = ? ")) {
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($user_id, $salt, $hashed_pw);
if(($stmt->fetch()) == 1) {
$entered_hashed_pw = sha1($salt . $password);
if ($entered_hashed_pw === $hashed_pw) {
$_SESSION['userid'] = $user_id;
$_SESSION['username'] = $username;
$sess_id = session_id();
$_SESSION['sessid'] = $sess_id;
header("Location: next_page.php");
$stmt->close();
$mysqli->close();
if (isset($sess_id) and ! empty ($sess_id)){
if (isset ($username) and ! empty ($username)){
// Code here...
}
else ...
}
else ...