Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,011 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,460 people online right now. Registration is fast and FREE... Join Now!




php encrypted login

 
Reply to this topicStart new topic

php encrypted login, login page comes up blank

tippps
12 Dec, 2006 - 08:23 PM
Post #1

New D.I.C Head
*

Joined: 12 Dec, 2006
Posts: 3


My Contributions
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:

CODE
<?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 Dec, 2006 - 07:39 AM
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Php Encrypted Login
12 Dec, 2006 - 09:17 PM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,304



Thanked: 101 times
Dream Kudos: 1275
My Contributions
When you view the page you get an error, what is this error? It will greatly help us help you smile.gif
User is online!Profile CardPM
+Quote Post

tippps
RE: Php Encrypted Login
13 Dec, 2006 - 03:58 PM
Post #3

New D.I.C Head
*

Joined: 12 Dec, 2006
Posts: 3


My Contributions
QUOTE(BetaWar @ 12 Dec, 2006 - 10:17 PM) *

When you view the page you get an error, what is this error? It will greatly help us help you smile.gif



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 Dec, 2006 - 05:47 PM
User is offlineProfile CardPM
+Quote Post

tippps
RE: Php Encrypted Login
15 Dec, 2006 - 09:32 AM
Post #4

New D.I.C Head
*

Joined: 12 Dec, 2006
Posts: 3


My Contributions
QUOTE(tippps @ 13 Dec, 2006 - 04:58 PM) *

QUOTE(BetaWar @ 12 Dec, 2006 - 10:17 PM) *

When you view the page you get an error, what is this error? It will greatly help us help you smile.gif



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
User is offlineProfile CardPM
+Quote Post

AdamG
RE: Php Encrypted Login
29 Dec, 2006 - 04:22 AM
Post #5

D.I.C Head
Group Icon

Joined: 12 Jan, 2005
Posts: 94



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(tippps @ 15 Dec, 2006 - 10:32 AM) *

QUOTE(tippps @ 13 Dec, 2006 - 04:58 PM) *

QUOTE(BetaWar @ 12 Dec, 2006 - 10:17 PM) *

When you view the page you get an error, what is this error? It will greatly help us help you smile.gif



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
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 08:59PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month