Jump to content

Advanced User Authorization and Login


Barzini

Recommended Posts

Hello, I'll get straight to the point :D (first topic, first post) please don't mind the noobishness ;)

 

I've got a user log in script that doesn't seem to want to work for me it is very frustrating...

 

 

~~corresponding codes snippet (functions.php)~~

function create_account ($handle,$password,$password2,$email,$email2,$test)
{
//check if any fields have been missed
if(!$handle or !$password or !password2 or !$email or $email2 or $test){
	$message = '<div class="red">Error, you are missing one or more form fields. Please fill all of them out completely.</div>';

//everything alright so far
} else {
	//password must match password2
	if($password != $password2){
		$message = '<div class="red">Error, you did not enter your passwords correctly.</div>';

} else {
        //email must match email2
	if($email != $email2){
		$message = '<div class="red">Error, you did not enter your emails correctly.</div>';

} else {
		$sql = 'SELECT * FROM `ws_users` WHERE username="' . $handle . '"';
		$query = queryme ($sql);
		$num_rows = mysql_num_rows($query);

		if($num_rows == 0){			
			$sql = 'INSERT INTO `ws_users` (`username`,`userpass`,`useremail`,`userip`,`signupdate`,`auth`, `test`) VALUES ("' . $handle . '","' . md5(md5(md5(md5($password)))) . '","' . $email . '","' . $_SERVER['REMOTE_ADDR'] . '","' . time() . '","1","' . $test . '")';
			$query = queryme ($sql);

			$message = '<div class="green">Successfully Created your account.<br />Please Login using the form to the right</div>';
		} else {
			$message = '<div class="red">Error, that handle is already in use.</div>';
		}
	}
}
return $message;
}
}

 

The password 1 and 2 and email 1 and 2 are for confirmation...

 

~~index.php~~

<?php
//index.php
//Allows users to create accounts, or login to accounts
//If logged in, redirect automatically to the lobby...

//Session handling & Page GZipping
session_start();
ob_start('ob_gzhandler');

//Includes:
require_once 'inc/connect.php';
require_once 'inc/class.php';
require_once 'inc/functions.php';

//Check wether user is logged in or not
if($_SESSION['loggedin']){
redirect('lobby.php');
}

//If we have an error note, display it under tabletwo
if($_GET['error']){
$page['tabletwo'] = '<div class="red">Error: ' . $_GET['error'] . '</div>';
}

//Check wether user has loggedin/signed up
if($_POST){
if($_POST['do'] == 'createaccount'){
	//Create Account
	 $page['tableone'] .= create_account ($_POST['handle'],$_POST['password'],$_POST['password2'],$_POST['email'],$_POST['email2'],$_POST['test']);
}
if($_POST['do'] == 'login'){
	//Login to Account
	$page['tabletwo'] .= login ($_POST['handle'],$_POST['password']);		
}
}

include 'templates/temp_index.php';
?>

 

~~temp_index.php~~

<body class="background">
<div align="center" class="body"> 
<!-- Header Table -->
<div id="overDiv" style="position: absolute; visibility: hidden; z-index: 1000;"></div>
<table width="735" class="layouttable">
  <tr>
    <td><div align="center"><img src="images/jpbanner.jpg" /></div></td>
  </tr>
</table>
<br />
<!-- Content Table -->
<table width="735" class="layouttable">
  <tr>
    <td>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
          <!--DWLayoutTable-->
          <tr> 
            <td width="100%" valign="top" class="dispkey">
		<div align="center"><a href="index.php">Index</a> | <a href="help.php" id="navlink">Rules</a> 
           </div>
		</td>
          </tr>
        </table>
	<br />
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	  <tr>
	    <td width="3%"> </td>
          <td width="46%" align="left" valign="top" class="dispkey"><strong>Create a new Account:</strong><br />
            <br />
		<form name="createaccount" action="index.php" method="post">
		<div align="center">
            <table width="90%" border="0">
              <tr>
                <td>Handle:</td>
                <td><input type="text" name="handle" class="form"></td>
			<td width="5%" onmouseover="return overlib('This is your SWC handle, it will be used to identify you within the Game. Please make sure it is a Valid Handle.', CAPTION, 'Handle',WIDTH,225);" onmouseout="return nd();"><b>?</b></td>
              </tr>
              <tr>
                <td>Password:</td>
                <td><input type="password" name="password" class="form"></td>
			<td onmouseover="return overlib('This is the the password that you want for this website.It is encrypted and stored in the Database. Nobody has access to it.', CAPTION, 'Password',WIDTH,225);" onmouseout="return nd();"><b>?</b></td>
              </tr>
              <tr>
                <td>Email:</td>
                <td><input type="text" name="email" class="form"></td>
			<td onmouseover="return overlib('This is your Email Address, It is used if you forget your password and need a new one emailed to you.', CAPTION, 'Email',WIDTH,225);" onmouseout="return nd();"><b>?</b></td>
              </tr>
		  <tr>
                <td colspan="2"><div align="center">
                      <input name="Submit" type="submit" id="Submit" value="Submit" class="form">
                      <input name="do" type="hidden" value="createaccount" />
                    </div></td>
              </tr>
            </table> 
		</div>
		</form>
            <?php echo $page['tableone']; ?>
          </td>
	    <td width="2%"> </td>
          <td width="46%" align="left" valign="top" class="dispkey"><strong>Login 
            to your Account:</strong><br />
            <br />
		<form name="loginaccount" action="index.php" method="post">
		<div align="center">
		<table width="90%" border="0">
              <tr>
                <td>Handle:</td>
                <td><input type="text" name="handle" class="form"></td>
			</tr>
		  <tr>
                <td>Password:</td>
                <td><input type="password" name="password" class="form"></td>
			</tr>
		  <tr>
                <td colspan="2"><div align="center">
                      <input name="Submit" type="submit" id="Submit" value="Submit" class="form">
                      <input name="do" type="hidden" value="login" />
                    </div></td>
              </tr>
            </table>
		</div>
		</form>
            <?php echo $page['tabletwo']; ?>
          </td>
	    <td width="3%"> </td>
	  </tr>
	</table>
    </td>
  </tr>
</table>
<br />
<br />
</body>
</html>

 

That is the code that I'm using, I took the header off of temp_index to keep the personal stuff out, I want the script to give an error if not all the fields are filled in, if the passwords don't match, if the emails don't match, if the handle is already in use (the username), and if the email is already in use, then how/where to add new if/else statements for what I just said?? :P

 

I've got another important related question but I wont post it till after this is sorted out, thanks so much to whomever helps me as soon as they can :-DD.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.