I started out my PHP programming years relying heavily on dreamweaver to do my database coding. At the beginning I was restricted in my abilities to what dreamweaver was capable of doing, yet over the years my abilities grew and I now only use it to do the repetitive grunt work.
One thing I could never figure out was how to create encrypted password security systems using dreamweaver and I just figured it out using md5 and it is a piece of cake. I am posting it because I could not find it on google and thought other people like me could be looking for the code. I am using Dreamweaver CS4 at this time, but I don’t think that will matter.
For this tutorial, simply use Dreamweaver to build your username/password insertion page and login page as normal and I will show what you need to modify to make it work.On to the code…
The code that inserts passwords into the database…..
$insertSQL = sprintf("INSERT INTO `admin` (admin_name, admin_pass, admin_level) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['admin_name'], "text"),
GetSQLValueString(md5($_POST['admin_pass']), "text"),
GetSQLValueString($_POST['admin_level'], "int"));
As you can see, I simply inserted md5 with a new bracket around it…. That’s it, it is inserted into DB as md5
The Login page
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=md5($_POST['password']);
$MM_fldUserAuthorization = "admin_level";
$MM_redirectLoginSuccess = "login_good.php";
$MM_redirectLoginFailed = "login_bad.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_mine, $mine);
$LoginRS__query=sprintf("SELECT admin_name, admin_pass, admin_level FROM `admin` WHERE admin_name=%s AND admin_pass=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $mine) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'admin_level');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
this is a standard Dreamweaver generated login page, on this line $password=$_POST['password']; , again I simply inserted md5 and the bracket - $password=md5($_POST['password']);
Thats it, Dreamweaver and md5, piece of cake
No comments:
Post a Comment