Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Help with md5

Guest
Sep 17, 2007 Sep 17, 2007

Copy link to clipboard

Copied

Hi, I have successfully added md5 to my membership join page and the password is encrypted in my database table. However, it does not go to the member page when successful. It adds all the data that was filled out in the form into the database table and then returns with the membership join page again but with the form empty. Here is my script.

<?php require_once('Connections/member.php'); ?>
<?php
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="choose_another_username.php";
$loginUsername = $_POST['username'];
$LoginRS__query = "SELECT loginname FROM member WHERE loginname='" . $loginUsername . "'";
mysql_select_db($database_member, $member);
$LoginRS=mysql_query($LoginRS__query, $member) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);

//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}

if (isset($_POST['password'])) {$_POST['password'] =
md5($_POST['password']);}

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 = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "newuser")) {
$insertSQL = sprintf("INSERT INTO member (loginname, password, lastname, firstname, street, suburb, `state`, postcode, email, phone, newsletter, changenotes) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['lastname'], "text"),
GetSQLValueString($_POST['firstname'], "text"),
GetSQLValueString($_POST['street'], "text"),
GetSQLValueString($_POST['suburb'], "text"),
GetSQLValueString($_POST['select'], "text"),
GetSQLValueString($_POST['postcode'], "int"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['phone'], "int"),
GetSQLValueString(isset($_POST['subscribeyes']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['changeyes']) ? "true" : "", "defined","'Y'","'N'"));

mysql_select_db($database_member, $member);
$Result1 = mysql_query($insertSQL, $member) or die(mysql_error());


$insertGoTo = "members_home.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

?>

I am also trying to add md5 to the loginpage but without success. I have been told what to add but I am unsure where to add or what to modify to make it work. Your help on both matters would be awesome. Here is the md5 addition that I was given

if (isset($_POST['password'])) {$_POST['password'] =
md5($_POST['password']);}

Here is my login script
<?php require_once('Connections/member.php'); ?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];

if (isset($_POST['password'])) {$_POST['password'] =
md5($_POST['password']);}

$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "members_home.php";
$MM_redirectLoginFailed = "failed_login.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_member, $member);

$LoginRS__query=sprintf("SELECT loginname, password FROM member WHERE loginname='%s' AND password='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $member) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";

//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 );
}
}
?>

Thanks everyone, I am a PHP nuffie and I really appreciate all the help!
TOPICS
Server side applications

Views

383
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 18, 2007 Sep 18, 2007

Copy link to clipboard

Copied

Shedlight wrote:
> Hi, I have successfully added md5 to my membership join page and the password
> is encrypted in my database table.

What size is the password column in your database? md5() creates a
32-digit hexadecimal string. You need VARCHAR(32) or CHAR(32).
Otherwise, your password will be truncated.

The position of your PHP code, by the way, looks OK.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 18, 2007 Sep 18, 2007

Copy link to clipboard

Copied

My password column is varchar (255). The password is registering with my table but the correct page is not navigated to.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 18, 2007 Sep 18, 2007

Copy link to clipboard

Copied

Shedlight wrote:
> Hi, I have successfully added md5 to my membership join page and the password
> is encrypted in my database table. However, it does not go to the member page
> when successful.

Does the member's page (members_home.php) have the Restrict Access to
Page server behavior applied to it? If so, that's why the page doesn't
load after registering a new user. The user needs to log in first.

> I am also trying to add md5 to the loginpage but without success.

The position of the md5 addition is OK, but the following section of
code looks suspect:

> $LoginRS__query=sprintf("SELECT loginname, password FROM member WHERE
> loginname='%s' AND password='%s'",
> get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername),
> get_magic_quotes_gpc() ? $password : addslashes($password));

It looks as though you're using an outdated version of Dreamweaver.
Apply any updaters, and build the page again.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 18, 2007 Sep 18, 2007

Copy link to clipboard

Copied

LATEST
Thanks David, both pages are working fine now. I updated my Dreamweaver version and rebuilt the pages and everything is doing what it is supposed too.
Thanks again!!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines