Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password verification

Status
Not open for further replies.

PhoenixDown

Programmer
Jul 2, 2001
279
CA
How do I check a username and password in a mysql database? I'm trying to make a user login form.
 
Did you mean the login and Password for MySQL or login and password for your form??? I can`t understand your question... Someone who has never served other is someone that has never lived...
 
I use 2 pages for authorization, one is straight HTML holding the login form, the second is an intermediate page which processes the data posted by the form...depending on the validity of the data it then redirects accordingly...
Code:
 the login page
----------------
<form action=&quot;doAuthuser.php&quot; method=&quot;post&quot; name=&quot;frmLogin&quot;>
	<table bgcolor=&quot;Gainsboro&quot; align=&quot;center&quot; cellspacing=&quot;2&quot; cellpadding=&quot;2&quot; border=&quot;0&quot;>
<tr>
    <th colspan=&quot;2&quot; align=&quot;center&quot;>System Login</th>
</tr>
<tr>
    <td><strong>UserName</strong></td>
    <td><input type=&quot;text&quot; name=&quot;frmLogin[username]&quot; size=&quot;12&quot; maxlength=&quot;12&quot;></td>
</tr>
<tr>
    <td><strong>Password</strong></td>
    <td><input type=&quot;password&quot; name=&quot;frmLogin[password]&quot; size=&quot;12&quot; maxlength=&quot;12&quot;></td>
</tr>
<tr colspan=&quot;2&quot;>
    <td align=&quot;left&quot;><input type=&quot;submit&quot; name=&quot;frmLogin[submit]&quot; value=&quot;Login&quot;></td>
    <td align=&quot;right&quot;><input type=&quot;Reset&quot;></td>
</tr>
</table>

	</form>
---------------
---------------

doAuthuser.php
-------------

<?php


// IF  the login form was sent

if(isset($_POST['frmLogin']))
{  
    $sql = &quot;SELECT username, password FROM auth_users WHERE username = '&quot; . 
    $_POST['frmLogin']['username'] . &quot;' AND password  = '&quot; . $_POST['frmLogin']['password'] .&quot;'&quot;;
    
    $result = mysql_query( $sql ) or die( mysql_error());
    if(!$result)// if no match in DB
    {
        echo &quot;No username or password matches your entry.  Please register.&quot;;
        /* ......redirect to registration page......   */
    }else{
        /* 
            do whatever you want to do for an authorized user here
            like:
            
             header(&quot;Location: pageOne.php&quot;);
          */
    }
    
}else{
    /*
    * test if the user hits this page via the login form
    * if test fails send them straight to login page
    */
    header(&quot;Location: login.php&quot;);
}

?>
---------
---------

HTH

Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top