I found this script at StarGeeks, and have a few questions about creating a registration and login form... i've already tried but had little sucess sadly,
oh, and one more question... in the MakeTableLogins at the bottom it creates the mysql_querry using pasword char, and not password... is this intentional?
oh, and one more question... in the MakeTableLogins at the bottom it creates the mysql_querry using pasword char, and not password... is this intentional?
PHP Code:
<?
function MakeTableLogins($database, $host, $db_user, $db_pass) {//create the logins table
$linkID = mysql_connect($host, $db_user, $db_pass);
mysql_select_db($database, $linkID);
mysql_query("create table logins (user char(32), pasword char(32))", $linkID);
}
function Encrypt($string) {//hash then encrypt a string
$crypted = crypt(md5($string), md5($string));
return $crypted;
}
function AddUser($database, $host, $db_user, $db_pass, $username, $password) { //add user to table logins
$linkID = mysql_connect($host, $db_user, $db_pass);
mysql_select_db($database, $linkID);
$password = encrypt($password);
$username = encrypt($username);
mysql_query("insert into logins values ('$username', '$password')", $linkID);
}
function Login($database, $host, $db_user, $db_pass, $user, $password) { //attempt to login false if invalid true if correct
$auth = false;
$user = Encrypt($user);
$linkID = mysql_connect($host, $db_user, $db_pass);
mysql_select_db("$database", $linkID);
$result = mysql_query("select password from logins where user = '$user'", $linkID);
$pass = mysql_fetch_row($result);
mysql_close($linkID);
if ($pass[0] === (Encrypt($password))) {
$auth = true;
}
return $auth;
}
?>
Comment