Forum Moderators: coopster

Message Too Old, No Replies

[PHP] login based mysql decision

         

jay7981

11:48 pm on Jun 6, 2009 (gmt 0)

10+ Year Member



I have a question and have recived great help thus far but i am almost positive what i want to do is not feesible...

i havent really worked with md5 before but i want to create a registration form that when you enter your username and guild it validates that info against what is in mysql (meaning that the information provided is in the same row) then allows for you to enter a password that will be saved in mysql as an md5 password.

Not sure how ecactly to begin this other than the actual form which i beleive will be a 2 part form 1st part asking for username and has a selection box pre-filled with array data and a next button, 2nd part asking for a password and a submit button posting to a sql query. also do i need to create the field in mysql for the password in any special way to accomodate the md5? also could all of this be embedded in a single script? or would it be better to do a seperate page for each?

then i want to create a login form (username, password, guild you are leader of{guild will be an array of mysql data}) and once this form is submitted i want to have it check each row for a solid match of information (username is on the same row as the inputed password and guild) then after successful login display results of "SELECT * from `table` WHERE status='Applicant' AND guild='guild from login'" with accept/deny buttons next to each result and which the accept will change the status to "Member" and the Deny will delete the record.

I know this is alot i have the basics (below) just not sure how to finish it up...

Registration Form 1:


<form id="reg1" name="reg1" method="post" action="">
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td><div align="right">Username:</div></td>
<td><div align="left">
<input type="text" name="username" id="username" />
</div></td>
</tr>
<tr>
<td><div align="right">Guild:</div></td>
<td><div align="left">
<?
$sql = "SELECT * FROM `table` WHERE status='Member'";
$options="";
$query = mysql_query($sql);
while ($row=mysql_fetch_array($query)) {

$id=$row["gname"];
$options.="<OPTION VALUE=\"$id\">".$id;
}
?>
<select name="gname" style="width:auto" id="gname">
<?=$options?>
</select>
</div></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><div align="left">
<input type="button" name="next" id="next" value="Next" />
</div></td>
</tr>
</table>
</form>

Registration Form 2:


<form id="reg2" name="reg2" method="post" action="">
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td><div align="right">Password:</div></td>
<td><div align="left">
<input type="password" name="password" id="password" />
</div></td>
</tr>
<tr>
<td><div align="right">Confirm Password:</div></td>
<td><div align="left">
<input type="password" name="password" id="password" />
</div></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><div align="left"></div></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><div align="left">
<input type="button" name="submit" id="submit" value="Submit" />
</div></td>
</tr>
</table>
</form>

Login Form:


<form id="login" name="login" method="post" action="">
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td><div align="right">Username:</div></td>
<td><div align="left">
<input type="text" name="username" id="username" />
</div></td>
</tr>
<tr>
<td><div align="right">Password:</div></td>
<td><div align="left">
<input type="password" name="password" id="password" />
</div></td>
</tr>
<tr>
<td><div align="right">Guild:</div></td>
<td><div align="left">
<?
$sql = "SELECT * FROM `table` WHERE status='Member'";
$options="";
$query = mysql_query($sql);
while ($row=mysql_fetch_array($query)) {

$id=$row["gname"];
$options.="<OPTION VALUE=\"$id\">".$id;
}
?>
<select name="gname" style="width:auto" id="gname">
<?=$options?>
</select>
</div></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><div align="left">
<input type="button" name="submit" id="submit" value="Login" />
</div></td>
</tr>
</table>
</form>

Habtom

4:50 am on Jun 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



  • You can just have the registration form 1 and 2 as one form
  • There is nothing much special about MD5, during registration store the password as md5($password) [php.net]
  • On the login page, you could compare md5($password just supplied)==password in the database, if the same allow the login to proceed.
  • jay7981

    7:15 am on Jun 7, 2009 (gmt 0)

    10+ Year Member



    ok that helped but yet at the same time it didnt ...

    jay7981

    10:31 pm on Jun 8, 2009 (gmt 0)

    10+ Year Member




    On the login page, you could compare md5($password just supplied)==password in the database, if the same allow the login to proceed.

    i have to have the mysql results ONLY display the guild info that the login matches
    example:
    Bob logs in as username bob and password bobspass and selects his guild bobsguild it will only display results of bobsguild that have status applicant, but if bob logs in as bob and password as bobspass and guild notbobsguild it will deny the login.

    anyway i can get some examples as how to do this ?

    jay7981

    3:51 pm on Jun 11, 2009 (gmt 0)

    10+ Year Member



    any help would be great!

    coopster

    10:15 pm on Jun 11, 2009 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    Have you made any attempts at writing the query yet? You take the posted username and password and securely use them to query your database table to authenticate the user. The password is going to be "encrypted" using the md5 hash so you need to use the same hash on the user-supplied password to compare against in the database table for that member.

    jay7981

    11:16 pm on Jun 11, 2009 (gmt 0)

    10+ Year Member



    yes i have and i dont have the experience with md5 nor can i understand the tutorials i have found enough to get it to work ..

    coopster

    11:21 pm on Jun 11, 2009 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    Well, you run your query and you can either compare during the query execution or check the value using php's md5 function. Something along these lines:
    if (md5($_POST['userPassword']) != $row['userPassword']) {

    jay7981

    2:07 am on Jun 15, 2009 (gmt 0)

    10+ Year Member



    ok i have created a page that i belive will work .. however the dang submit button wont work ... can i get a fresh set of eyes look at this please...


    <!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=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form id="login" name="login" method="post" target="_self" action="./sql/guild_login.php">
    <table width="100%" border="0" cellspacing="3" cellpadding="3">
    <tr>
    <td><div align="right">Username:</div></td>
    <td><div align="left">
    <input type="text" name="username" id="username" />
    </div></td>
    </tr>
    <tr>
    <td><div align="right">Password:</div></td>
    <td><div align="left">
    <input type="password" name="password" id="password" />
    </div></td>
    </tr>
    <tr>
    <td><div align="right">Guild:</div></td>
    <td><div align="left">
    <?php
    $host="localhost";
    $username="#*$!X";
    $password="#*$!X";
    $db_name="#*$!X";

    mysql_connect("$host", "$username", "$password")or die("<br />Connect-". mysql_error());
    mysql_select_db("$db_name")or die("<br />Select DB-". mysql_error());
    $sql = "SELECT * FROM `sun_alliance` WHERE status='Member'";

    $query = mysql_query($sql);
    while ($row=mysql_fetch_array($query)) {

    $id=$row["gname"];
    $options.="<option value='$id'>$id</option>";
    }
    ?>
    <select name="gname">
    <option>Please Select</option>
    <?php print($options);?>
    </select>
    </div></td>
    </tr>
    <tr>
    <td><div align="right"></div></td>
    <td><div align="left">
    <input name="login" type="button" value="Login" />
    </div></td>
    </tr>
    </table>
    </form>
    <p> <a href="http://validator.w3.org/check?uri=referer"><img
    src="http://www.w3.org/Icons/valid-xhtml10"
    alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a> </p>
    </body>
    </html>

    Habtom

    4:47 am on Jun 15, 2009 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Change:
    <input name="login" type="button" value="Login" />
    to
    <input name="login" type="submit" value="Login" />

    jay7981

    6:49 am on Jun 15, 2009 (gmt 0)

    10+ Year Member



    oh geez! are u serious ... i need to shoot myself LOL ...