RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 355 | Replies: 7 | Solved | Thread Tools  Display Modes
Reply
Join Date: Aug 2007
Posts: 64
Reputation: nil_gh_80 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nil_gh_80's Avatar
nil_gh_80 nil_gh_80 is offline Offline
Junior Poster in Training

***** User Login problem *****

  #1  
Dec 1st, 2008
Hello friends,

I've a user login system......user's name & password are saved in the database.......suppose i've an user "admin". At the time of login if he enters "admin" he can login also if enters "ADMIN" or "AdMiN" he can login too.....how can I stop this thing........PLZZZZZZZ show me the way......

thank you...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 177
Reputation: cwarn23 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
cwarn23 cwarn23 is offline Offline
Junior Poster

Re: ***** User Login problem *****

  #2  
Dec 1st, 2008
For that you could just convert both values to lower case with strtolower(); So try the following and I have included the form.
<?
//mysql connections
$username='Admin'; //from mysql in your script

$username=strtolower($username);
if (isset($_POST['username']))
    {
    $_POST['username']=strtolower($_POST['username']);
    if ($_POST['username']==$username)
        {
        //login
        }
    }
?>
<form method='post'>
<input type='text' value='adMiN' name='username'>
<input type='submit' value='submit'>
</form>
Signature note:
Do not edit the registry just because someone on the forum says so. Do some research on the internet before editing the registry.
Reply With Quote  
Join Date: Aug 2007
Posts: 64
Reputation: nil_gh_80 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nil_gh_80's Avatar
nil_gh_80 nil_gh_80 is offline Offline
Junior Poster in Training

Re: ***** User Login problem *****

  #3  
Dec 1st, 2008
sorry man this is not that i want ......actually i want to check the string insterted case sensitive way......
Reply With Quote  
Join Date: Sep 2007
Posts: 177
Reputation: cwarn23 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
cwarn23 cwarn23 is offline Offline
Junior Poster

Re: ***** User Login problem *****

  #4  
Dec 1st, 2008
If you want it case sensitive then because php is case sensitive, just get php to check if the 2 values = each other. So use the following:
  1. <?
  2. //mysql connections
  3. $username='Admin'; //from mysql in your script
  4.  
  5. if (isset($_POST['username']) && $_POST['username']==$username)
  6. {
  7. //login
  8. echo "test";
  9. }
  10. ?>
  11. <form method='post'>
  12. <input type='text' value='adMiN' name='username'>
  13. <input type='submit' value='submit'>
  14. </form>
Signature note:
Do not edit the registry just because someone on the forum says so. Do some research on the internet before editing the registry.
Reply With Quote  
Join Date: Aug 2007
Posts: 64
Reputation: nil_gh_80 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nil_gh_80's Avatar
nil_gh_80 nil_gh_80 is offline Offline
Junior Poster in Training

Re: ***** User Login problem *****

  #5  
Dec 1st, 2008
according to your solution if I have 1,00,00,000 user will I define those user in that number of veriables ?????????? is this thing feasible ?????????
Reply With Quote  
Join Date: Sep 2007
Posts: 177
Reputation: cwarn23 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
cwarn23 cwarn23 is offline Offline
Junior Poster

Re: ***** User Login problem *****

  #6  
Dec 1st, 2008
Originally Posted by nil_gh_80 View Post
according to your solution if I have 1,00,00,000 user will I define those user in that number of veriables ?????????? is this thing feasible ?????????

Yes because all you need to do is check that the username (which should be unique from all the others) is correct and that at option, the password for security reasons is correct. So just to explain, I shall write a basic login system for you.

Below is login.php
  1. session_start();
  2. //mysql connect code
  3.  
  4. $result=mysql_query("SELECT * FROM `users` WHERE `username`='".$_POST['username']."' AND `password`='".$_POST['password']."'");
  5.  
  6. if (isset($_POST['username']) && mysql_num_rows($result)==1)
  7. {
  8. $row=mysql_fetch_array($result);
  9. $_SESSION['username111']==$row['username'];
  10. unset($row);
  11. header('Location: index.php?login=true');
  12. //there should be no browser output before this line.
  13. }
  14. ?>
  15. <form method='post'>
  16. <input type='text' value='Admin' name='username'><br>
  17. <input type='text' value='password' name='password'>
  18. <input type='submit' value='submit'>
  19. </form>

index.php (at top)
  1. <?
  2. session_start();
  3. if ($_GET['login']=='true' && !isset($_SESSION['username111']))
  4. {
  5. echo "<h1>You need to be logged in to view this page!</h1>";
  6. exit;
  7. }
  8. //no browser output before this line.
Sorry if there is a small bug but that login system is from the top of my head and I have used simular ones in the past. Hope that example helps
Signature note:
Do not edit the registry just because someone on the forum says so. Do some research on the internet before editing the registry.
Reply With Quote  
Join Date: Nov 2008
Location: Dumaguete, Philippines
Posts: 24
Reputation: xarz is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
xarz's Avatar
xarz xarz is offline Offline
Newbie Poster

Re: ***** User Login problem *****

  #7  
Dec 1st, 2008
@cwarn23 yeah, I agree with your code also.. I use it the same way.. just add htmlentities to make sure that there will be no sql injections..
:: xarz ::
Reply With Quote  
Join Date: Apr 2008
Posts: 171
Reputation: Aamit is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 5
Aamit Aamit is offline Offline
Junior Poster

Re: ***** User Login problem *****

  #8  
Dec 2nd, 2008
here you can use md5 encrypted password....
when you use md5 you got this value in database
admin= 21232f297a57a5a743894a0e4a801fc3

ADMIN= 73acd9a5972130b75066c82595a1fae3 

AdMiN= 2714cba6c6d58e587565cf4e6b275078 


login.php
$con = mysql_connect("localhost","root","");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }
	  else
	  {
	 // echo('Connected with Mysql');
	  }
		@mysql_select_db("db_login", $con);
		if (isset($_POST['Submit']))
		{
			$user_uname=$_POST["user_uname"];
			$user_pass=md5($_POST["user_pass"]);
											
			
			$sql=mysql_query("SELECT * FROM table WHERE user_uname='$user_uname' AND user_pass='$user_pass'");
			
			if (mysql_num_rows($sql)==0 || mysql_num_rows($sql)>1)
			{	
				echo "<script>alert('Username/password pair is invalid.Please try again.')</script>";
				
				echo"<script language='javascript'>window.location.href='login.php'</script>";
			}
			while($row = mysql_fetch_array($sql))
				  {
					if($user_pass==$row['user_pass'] and $user_uname==$row['user_uname'])
					{
						//here use go to your new page						echo"<script language='javascript'>window.location.href='newprofile.php'</script>";
						}
						else
						{
													echo"<script language='javascript'>window.location.href='login.php'</script>";
						}
					}
				  }
				  echo"<script language='javascript'>window.location.href='login.php'</script>";
		} 
}

when use register or save data in mysql / databse
you have to insert data like...
$sql="INSERT INTO table ( user_uname, user_pass) VALUES('$_POST[user_uname]','md5($_POST[user_pass])')";
i think this solves your problem.......
Last edited by Aamit : Dec 2nd, 2008 at 6:11 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the PHP Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:07 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC