php encrypted login

login page comes up blank

Page 1 of 1

4 Replies - 2676 Views - Last Post: 29 December 2006 - 05:22 AM Rate Topic: -----

#1 tippps  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-December 06

php encrypted login

Post icon  Posted 12 December 2006 - 09:23 PM

anopther PHP MySQL newbie here.
trying to create an encrypted login page which dreamweaver doesnt give me the option to do!
i found a template and pasted it in a new blank page, created the username/password fields, submit button,etc and added the "login user" server behavior and configured it with my DB connection, table, and fields, etc.
i just dont know enough (or anything for that matter) about the code to decipher what part is going wrong.
the code is as follows:

<?php virtual('/Connections/tippps.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
?>
<?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'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "/Tippps/submission.php";
  $MM_redirectLoginFailed = "/Tippps/LoginFailed.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_tippps, $tippps);
  
  $LoginRS__query=sprintf("SELECT UserName, Password FROM register WHERE UserName=%s AND Password=%s",
	GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $tippps) 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 );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
  <table width="245" border="1">
	<tr>
	  <td colspan="2"><img src="login_sm.JPG" alt="" width="17" height="16" /> Login </td>
	</tr>
	<tr>
	  <td width="54">Username</td>
	  <td width="175"><input name="username" type="text" /></td>
	</tr>
	<tr>
	  <td>Password</td>
	  <td><input name="password" type="password" /></td>
	</tr>
	<tr>
	  <td colspan="2"><div align="center">
		<input type="submit" name="Submit" value="Submit" />
	  </div></td>
	</tr>
	<tr>
	  <td colspan="2"><div align="center" class="style1">Forgot your password? </div></td>
	</tr>
  </table>
  <?
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;
}
?>
</form>
</body>
</html>


any help will be soooooo appreciated! i really am at the point of commiting a felony here people!


[mod edit] Please use the code tags!

This post has been edited by hotsnoj: 13 December 2006 - 08:39 AM


Is This A Good Question/Topic? 0
  • +

Replies To: php encrypted login

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 920
  • View blog
  • Posts: 6,443
  • Joined: 07-September 06

Re: php encrypted login

Posted 12 December 2006 - 10:17 PM

When you view the page you get an error, what is this error? It will greatly help us help you :)
Was This Post Helpful? 0
  • +
  • -

#3 tippps  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-December 06

Re: php encrypted login

Posted 13 December 2006 - 04:58 PM

View PostBetaWar, on 12 Dec, 2006 - 10:17 PM, said:

When you view the page you get an error, what is this error? It will greatly help us help you :)



Actually i dont get an error at all. the page is just blank. i got the same pronlem when i tried to create a login form on my index page. once i added the form and server beavior in Dreanweaver the page would load completely blank! as soon as i removed the form the page would load just fine.
Sorry, but there is no error to tell you of.

(update)--- the instant i add a form to the page it loads blank in a IE. when i remove the form the table that i created for login fields loads fine...
hope that hekps with an aswer
thank you!!!

This post has been edited by tippps: 13 December 2006 - 06:47 PM

Was This Post Helpful? 0
  • +
  • -

#4 tippps  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-December 06

Re: php encrypted login

Posted 15 December 2006 - 10:32 AM

View Posttippps, on 13 Dec, 2006 - 04:58 PM, said:

View PostBetaWar, on 12 Dec, 2006 - 10:17 PM, said:

When you view the page you get an error, what is this error? It will greatly help us help you :)



Actually i dont get an error at all. the page is just blank. i got the same pronlem when i tried to create a login form on my index page. once i added the form and server beavior in Dreanweaver the page would load completely blank! as soon as i removed the form the page would load just fine.
Sorry, but there is no error to tell you of.

(update)--- the instant i add a form to the page it loads blank in a IE. when i remove the form the table that i created for login fields loads fine...
hope that hekps with an aswer
thank you!!!


another update - actually its when i add the server behavior "login user" the page will then load blank in a browser
Was This Post Helpful? 0
  • +
  • -

#5 AdamG  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 95
  • Joined: 12-January 05

Re: php encrypted login

Posted 29 December 2006 - 05:22 AM

View Posttippps, on 15 Dec, 2006 - 10:32 AM, said:

View Posttippps, on 13 Dec, 2006 - 04:58 PM, said:

View PostBetaWar, on 12 Dec, 2006 - 10:17 PM, said:

When you view the page you get an error, what is this error? It will greatly help us help you :)



Actually i dont get an error at all. the page is just blank. i got the same pronlem when i tried to create a login form on my index page. once i added the form and server beavior in Dreanweaver the page would load completely blank! as soon as i removed the form the page would load just fine.
Sorry, but there is no error to tell you of.

(update)--- the instant i add a form to the page it loads blank in a IE. when i remove the form the table that i created for login fields loads fine...
hope that hekps with an aswer
thank you!!!


another update - actually its when i add the server behavior "login user" the page will then load blank in a browser

Everytime I've run across this it's due to errors in my PHP. So I would go over your functions and such with a fine toothed comb and see if you can't find an error. :shrug:

--Adam
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1