Welcome to Dream.In.Code
Getting PHP Help is Easy!

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




PHP login issues

 
Reply to this topicStart new topic

PHP login issues

jeansymolanza
27 Feb, 2008 - 10:01 AM
Post #1

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
CODE

<?php require_once('../Connections/ilovephysics.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['email'])) {
  $loginUsername=$_POST['email'];
  $password=$_POST['password'];
  
//encode password
$encpassword = md5($loginUsername + $password);
  
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "../buy/user.php";
  $MM_redirectLoginFailed = "loginfail.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_ilovephysics, $ilovephysics);
  
  $LoginRS__query=sprintf("SELECT email, password FROM tbl_users WHERE email='%s' AND password='%s'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $encpassword : addslashes($encpassword));
  
  $LoginRS = mysql_query($LoginRS__query, $ilovephysics) 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 k0b13r! I was able to encrypt all passwords on POST of edited and newly added users. But because the web app has to compare the encrypted password with the unencrypted password on login, I've found that my secondary admin account won't log on (I have yet to encrypt the primary admin account). Above I've included the login PHP code. I've tried to adjust it slightly to reflect the changes but login's still fail. Any help would be appreciated.

Thanking you in advance!

This post has been edited by jeansymolanza: 27 Feb, 2008 - 10:05 AM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: PHP Login Issues
27 Feb, 2008 - 10:41 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,212



Thanked: 216 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
From the way it sounds it sounds like you are going from an unencrypted setup to an encrypted one where all the passwords are encrypted. If that is the case, to correct your issue, you are going to have to go through all the accounts (preferably using a script) that will read in the username and password, encrypt it, and then set the password to that value. Then you can work on the login script to match them up.

Because you are right, if you are encrypting the string and trying to compare, you will have to first query the record from the database for the username and pass that matches what they supplied, concatenate the values together, encrypt it, and then put it back into the database. You could do that or if it was me, I would just run a quick script that does all account encryptions and be done with it.

I hope I am making some sense to you. smile.gif
User is online!Profile CardPM
+Quote Post

Realcoder
RE: PHP Login Issues
27 Feb, 2008 - 10:59 PM
Post #3

New D.I.C Head
*

Joined: 26 Feb, 2008
Posts: 5

Do you want to learn PHP/.NEt/JAVA/ERP/SAP/...... ???

Download EBooks Freely in .pdf,.chm formats and ready for interview questions....

-Spam link removed-

Download Opensource CMS Freely

-Spam link removed-

Project management System in PHP - MySQL -
-Spam link removed-

content management systems -
-Spam link removed-
User is offlineProfile CardPM
+Quote Post

bhandari
RE: PHP Login Issues
27 Feb, 2008 - 11:04 PM
Post #4

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
i fear that is not copyright protected.

seems like your posting something violating IPR laws. I can't open them as blogger is blocked at my place. Edit your post to remove all copyright material links.

Here's the other thread where you posted the same.
http://www.dreamincode.net/forums/index.ph...mp;#entry317069
User is offlineProfile CardPM
+Quote Post

Mike007
RE: PHP Login Issues
27 Feb, 2008 - 11:15 PM
Post #5

D.I.C Head
Group Icon

Joined: 30 Aug, 2007
Posts: 205


Dream Kudos: 75
My Contributions
Just to let you know that you are getting the md5 hash of 0 everytime you run this script. Because in PHP unlike in other languages the plus(+) is a math operation but not a concat one. So it will result in zero, had the same problem a few days ago, it is really hard to spot because it seems to be working fine until you check the value :S.

This line:
CODE

//encode password
$encpassword = md5($loginUsername + $password);


P.S
Can't believe marty missed this one lol smile.gif.
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: PHP Login Issues
27 Feb, 2008 - 11:24 PM
Post #6

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(Mike007 @ 28 Feb, 2008 - 12:15 AM) *

Just to let you know that you are getting the md5 hash of 0 everytime you run this script. Because in PHP unlike in other languages the plus(+) is a math operation but not a concat one. So it will result in zero, had the same problem a few days ago, it is really hard to spot because it seems to be working fine until you check the value :S.

This line:
CODE

//encode password
$encpassword = md5($loginUsername + $password);


P.S
Can't believe marty missed this one lol smile.gif.

To concatenate you use the dot.

Although, I've never seen anyone scramble a password up exactly like this...
User is online!Profile CardPM
+Quote Post

SpaceMan
RE: PHP Login Issues
28 Feb, 2008 - 11:20 AM
Post #7

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

to add a little filtering for security.

change all pages that input/check user name password.
or make a function. function is prefered. so all are the same.
php

function clean_input($input,$chrs = '',$with = '') {
//and char found that are not alloud are replaced $with
return eregi_replace("[^A-Z,0-9,_%".$chrs."]", $with, $input);
}

function hash_password($loginUsername,$password){
//clean and hash password
return(md5(clean_input(urlencode($loginUsername)).clean_input($password)));
}
$hashed_password = hash_password($_POST['email'],$_POST['password']);


This post has been edited by SpaceMan: 28 Feb, 2008 - 11:24 AM
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: PHP Login Issues
28 Feb, 2008 - 11:37 AM
Post #8

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

just noticed md5 is case sensative.

to try and idiot proof it....
php

function clean_input($input,$chrs = '',$with = '') {
//and char found that are not alloud are replaced $with
return eregi_replace("[^A-Z,0-9,_".$chrs."]", $with, $input);
}

function hash_password($loginUsername,$password){
//clean and encode password
return(md5(strtolower(clean_input($loginUsername)).clean_input($password)));

}

User is offlineProfile CardPM
+Quote Post

jeansymolanza
RE: PHP Login Issues
28 Feb, 2008 - 02:15 PM
Post #9

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
Thanks a lot guys, I've given it a shot using your advice SpaceMan and it seems to be working. Although I'm only building a school site I'm hoping to eliminate all security threats.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:26PM

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