md5 kryptering af password inden det smides i databasen
Jeg benytter login-scriptet fra www.sukos.dk, og er ved at lave en mindre admin-del, hvor man skal tilføje ny bruger osv.Jeg har lavet følgende script, som bare smider bruger og password i databasen. Jeg kunne godt tænke mig, at kryptere password med md5 inden det kommer i databasen.
Hvad skal jeg tilføje her?
<?php require_once('.././Connections/local2.php'); ?>
<?php require("../admin/tjeklogin.php"); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO brugere (navn, password) VALUES (%s, %s)",
GetSQLValueString($HTTP_POST_VARS['navn'], "text"),
GetSQLValueString($HTTP_POST_VARS['password'], "text"));
mysql_select_db($database_local2, $local2);
$Result1 = mysql_query($insertSQL, $local2) or die(mysql_error());
$insertGoTo = "/admin/admin.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<title>indtast post</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/greenstyle1.css" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<div id="Layer1" style="Z-INDEX: 1; LEFT: 149px; WIDTH: 273px; POSITION: absolute; TOP: 4px; HEIGHT: 23px"><em><strong><font size="2">Opret
ny bruger</font></strong></em></div>
<div align="left"><em><strong><font size="2"> </font></strong></em></div>
<p align="center"> </p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<div align="center">
<table width="930" align="left">
<tr valign="baseline">
<td height="24" align="right" nowrap> </td>
<td align="right" nowrap><div align="left"><strong><em>Brugeroplysninger:</em></strong></div></td>
<td> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td width="95" height="21" align="right" nowrap> </td>
<td width="229" align="right" nowrap><div align="left">Brugernavn:</div></td>
<td width="487"><input name="navn" size="50" maxlength="100" ></td>
<td width="99"> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap> </td>
<td align="right" nowrap><div align="left">Password:</div></td>
<td><input name="password" size="50" maxlength="100" ></td>
<td> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap><div align="left"></div></td>
<td align="right" nowrap> </td>
<td colspan="2"><input type="submit" value="Tilføj den nye bruger"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</div>
</form>
<p align="center"> </p>
</body>
</html>
