View Full Version : Login Need Help
sytodave88
10-10-2005, 09:05 PM
Hi I am Lookinng For the Following
Login page thats uses cookies and checks to see if users has actvated his/her accounts and also checks for username and passwrod in the database
Registrations page thats lets the user sign up and then send him a email with accavsion link also have the fileds
username
password
email adress
gender option male or female
country
Dave Smith-Haye
10-10-2005, 09:56 PM
Okay, asuming you have a MySQL Connect file, I am going to make a register for you, because I'm that nice of a guy.
<?php
include('connect.php');
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$country = $_POST['country'];
if(!$username){
echo"You forgot a username!";
}else{
$u = true;
}
if(!$password){
echo"You forgot a password!";
}else{
$p = true;
}
if(!$email){
echo"You forgot an email!";
}else{
$e = true;
}
///I didn't decide to make sure Gender and Country where submitted, because they could be edited in the profile
if($u && $p && $e){
$query = "INSERT INTO users VALUES username, password, email, gender, country AS $username, $password, $email, $gender, $country";
$result = mysql_query($query);
echo"Sign Up Complete!";
}else{
echo"Something failed. Please retry";
}
There you go.
700lbGorilla
10-10-2005, 10:08 PM
While that is a simple start, make sure you check to see if there are other usernames of that username in the database. Have two password fields to make sure they didn't miss type there password and comapre the two. Make sure your email field is protected against injection attacks (http://http://www.codingforums.com/showthread.php?t=68919). With the login, cookies are nice, but once you verify the cookie, switch to sessions.
Dave Smith-Haye
10-10-2005, 10:11 PM
Yeah, he didn't specify an email check, and I was just too darn lazy to do a check in the DB. And I forgot to insert an ID...
That's just pure laziness.
700lbGorilla
10-10-2005, 10:26 PM
Yeah, he didn't specify an email check, and I was just too darn lazy to do a check in the DB. And I forgot to insert an ID...
That's just pure laziness.
Nothing against your code, I didn't expect anyone to code the whole thing for him. Was just making sure he thought about doing those things. As you get further along we will be glad to help you tweak your code sytodave.
Dave Smith-Haye
10-10-2005, 11:24 PM
Yes. And I enjoy making full scripts, not parts of a script, because people jsut end up asking for the whoel thing.
sytodave88
10-11-2005, 04:52 PM
i am wanting the whole thing
700lbGorilla
10-11-2005, 07:50 PM
There you go then Dave, :thumbsup: I myself would rather help some one with problems, rather than do it all for them.
dave64
10-11-2005, 08:17 PM
Does your server run MYSQL?
Dave Smith-Haye
10-11-2005, 09:35 PM
There you go then Dave, :thumbsup: I myself would rather help some one with problems, rather than do it all for them.
But see, I'm going to explain it, just let me write the script, run it, than I will PM it.
:)
on second thought...not that I can't do it or anything. I have things to do, websites to make...
I'm just a teenager, I have a life outside of my computer...not saying yo uguys don't...just, you know, if I ever gert aroudn to makign it, I'll PM you it.
REMIYA
10-12-2005, 03:16 AM
Here is a little modification of the code above:
<?php
include('connect.php');
if(isset($_POST['username'])&$_POST['username']!=""){
$username = $_POST['username'];
}else{
echo"You forgot a username!";
exit;
}
....
MORE CODE HERE PASSWORD, etc.
....
if($username && $password && etc.){
.....
YOUR LOGIN CODE HERE
.....
}else{
echo"Something failed. Please retry";
exit;
}
dave64
10-12-2005, 03:01 PM
Look this over, there are Includes that I would have to send you. This uses a MYSQL database, has user signup, and a cookie that remembers them on the next visit. I'll also send you the SQL queries to create the tables and users. This should help you get started.
<?
/**
* Checks whether or not the given username is in the
* database, if so it checks if the given password is
* the same password in the database for that user.
* If the user doesn't exist or if the passwords don't
* match up, it returns an error code (1 or 2).
* On success it returns 0.
*/
function confirmUser($username, $password){
global $conn;
/* Add slashes if necessary (for query) */
if(!get_magic_quotes_gpc()) {
$username = addslashes($username);
}
/* Verify that user is in database */
$q = "select password from users where username = '$username'";
$result = mysql_query($q,$conn);
if(!$result || (mysql_numrows($result) < 1)){
return 1; //Indicates username failure
}
/* Retrieve password from result, strip slashes */
$dbarray = mysql_fetch_array($result);
$dbarray['password'] = stripslashes($dbarray['password']);
$password = stripslashes($password);
/* Validate that password is correct */
if($password == $dbarray['password']){
return 0; //Success! Username and password confirmed
}
else{
return 2; //Indicates password failure
}
}
/**
* checkLogin - Checks if the user has already previously
* logged in, and a session with the user has already been
* established. Also checks to see if user has been remembered.
* If so, the database is queried to make sure of the user's
* authenticity. Returns true if the user has logged in.
*/
function checkLogin(){
/* Check if user has been remembered */
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){
$_SESSION['username'] = $_COOKIE['cookname'];
$_SESSION['password'] = $_COOKIE['cookpass'];
}
/* Username and password have been set */
if(isset($_SESSION['username']) && isset($_SESSION['password'])){
/* Confirm that username and password are valid */
if(confirmUser($_SESSION['username'], $_SESSION['password']) != 0){
/* Variables are incorrect, user not logged in */
unset($_SESSION['username']);
unset($_SESSION['password']);
return false;
}
return true;
}
/* User not logged in */
else{
return false;
}
}
/**
* Determines whether or not to display the login
* form or to show the user that he is logged in
* based on if the session variables are set.
*/
function displayLogin(){
global $logged_in;
if($logged_in){
echo "<h1>Logged In!</h1>";
echo "Welcome <b>$_SESSION[username]</b>, you are now logged in to the MMI Secure site. <A HREF=\"/path to main page/index.htm\">Secure Site</a>";
}
else{
?>
</head>
<BODY>
<DIV ALIGN=CENTER>
<B><font color="RED" size="6" face="Times New Roman">ABCDEF INC</font></b>
<P>
<font size=3><b><img border="0" src="images/redlock.jpg" width="9" height="9"> You have requested access to the Associate Secure Area
<img border="0" src="images/redlock.jpg" width="9" height="9"></b></font>
</DIV>
<P>
<HR>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="535">
<tr>
<td>
<p align="center"> </p>
<p>
<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="03">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember">
<font size="2">Remember me next time</td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="sublogin" value="Login"></td></tr>
<table width="91%" border="0" cellspacing="5" cellpadding="3" bgcolor="#6699ff" align="center">
<tr align="center">
<td colspan="3" height="9">
<p><font face="Arial, Helvetica, sans-serif" size="2" color="darkblue">
<STRONG>
Please enter your credentials below
</STRONG>
</font></p>
</td>
</tr>
<tr>
<td align="right" width="40%" height="14">
<p><b><font face="Arial, Helvetica, sans-serif" size="2" color="#ffffff">
Username: </font></b></p>
</td>
<td height="14" align="right"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#ffffff">
<input name="username" size="20">
</font></b></td>
<td height="14"><IMG src="images/spacer.gif" width="90" height="1" alt=""></td>
</tr>
<tr>
<td align="right" width="40%" height="26">
<p><b><font face="Arial, Helvetica, sans-serif" size="2" color="#ffffff">Password:</font></b></p>
</td>
<td height="26" align="right"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#ffffff">
<input type="password" name="password" size="20">
</font></b></td>
<td height="14"><IMG src="images/spacer.gif" width="90" height="1" alt=""></td>
</tr>
<tr>
<td align="center" width="40%" height="42"> </td>
<td height="42" align="right"><b><font color="#ffffff"> <INPUT type=image alt=Login
src="images/loginbutton.gif" align=middle name=I1 width="72" height="22">
</font></b></td>
<td height="14"><IMG src="images/spacer.gif" width="90" height="1" alt=""></td>
</tr>
</table>
</form>
<br>
<div align="center">
<center>
<table border="0" cellspacing="5" cellpadding="5" width="91%">
<tr>
<td width="256"><font face="Arial, Helvetica, sans-serif" size="2">Problems?</font><font face="Arial, Helvetica, sans-serif" size="1"><br>
Note that both the user name and password are case sensitive. If you
continue to have trouble logging in to this area, please
contact the Webmaster.</font></td>
<td width="259" valign="top"><font face="Arial, Helvetica, sans-serif" size="2">Already
logged in?</font><font face="Arial, Helvetica, sans-serif" size="1"><br>
You may be presented with this page if you have not used your account
for over twenty minutes. Users are automatically logged out after twenty minutes
of inactivity. </font></td>
</tr>
</table>
</center>
</div>
<p> </td>
</tr>
<tr>
<td><font face="Arial, Helvetica, sans-serif" size="1" color="#6699ff">©
2005, ABCDEF, Inc.</font></td>
</tr>
</table>
</center>
/**
*<h1>Login</h1>
*<form action="" method="post">
*<table align="left" border="0" cellspacing="0" cellpadding="03">
*<tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
*<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
*<tr><td colspan="2" align="left"><input type="checkbox" name="remember">
*<font size="2">Remember me next time</td></tr>
*<tr><td colspan="2" align="right"><input type="submit" name="sublogin" value="Login"></td></tr>
*</table>
*</form>
*/
<?
}
}
/**
* Checks to see if the user has submitted his
* username and password through the login form,
* if so, checks authenticity in database and
* creates session.
*/
if(isset($_POST['sublogin'])){
/* Check that all fields were typed in */
if(!$_POST['user'] || !$_POST['pass']){
die('You didn\'t fill in a required field.');
}
/* Spruce up username, check length */
$_POST['user'] = trim($_POST['user']);
if(strlen($_POST['user']) > 30){
die("Sorry, the username is longer than 30 characters, please shorten it.");
}
/* Checks that username is in database and password is correct */
$md5pass = md5($_POST['pass']);
$result = confirmUser($_POST['user'], $md5pass);
/* Check error codes */
if($result == 1){
die('That username doesn\'t exist in our database.');
}
else if($result == 2){
die('Incorrect password, please try again.');
}
/* Username and password correct, register session variables */
$_POST['user'] = stripslashes($_POST['user']);
$_SESSION['username'] = $_POST['user'];
$_SESSION['password'] = $md5pass;
/**
* This is the cool part: the user has requested that we remember that
* he's logged in, so we set two cookies. One to hold his username,
* and one to hold his md5 encrypted password. We set them both to
* expire in 100 days. Now, next time he comes to our site, we will
* log him in automatically.
*/
if(isset($_POST['remember'])){
setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/");
setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/");
}
/* Quick self-redirect to avoid resending data on refresh */
echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
return;
}
/* Sets the value of the logged_in variable, which can be used in your code */
$logged_in = checkLogin();
sytodave88
10-12-2005, 03:23 PM
the scripts are for an texted based game like ny-mafia bootleggers
Dave Smith-Haye
10-12-2005, 09:05 PM
Like www.mobfather.com ?
jon.php
10-12-2005, 10:11 PM
Bro, you are coming here asking for a full blown script? Your post ("I want both")
was awfully rude, not even a thank you.
Since I'm not one to just criticize, www.pixel2life.com probaly has a good tutorial.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.