login/register/logout scripts

View previous topic View next topic Go down

grimofdoom
grimofdoom
Member
Member
Forum Posts : 106
Member Since : 2012-03-06

Postgrimofdoom 6/4/2012, 6:29 pm

I really need scripts that work for register,login and logout pages(php/mysql).I am completely new to php/mysql and know only enough of start/end of php section.can someone please give me scripts(non-download and simple username/pass) for this.if you could also put areas of change to show what i need to change it to,thank you.
Coddy
Coddy
Member
Member
Forum Posts : 45
Member Since : 2011-11-21

PostCoddy 7/4/2012, 5:25 pm

You want it to forumotion?
LGforum
LGforum
Moderator
Forum Posts : 77
Member Since : 2011-11-12

PostLGforum 7/4/2012, 9:56 pm

There's quite a reasonable amount in terms of creating a secure log in and registration. Here's a few things to get you started.

I am going to assume you know enough about HTML forms and how they are sent to php.

You'll also have to create your database users table.
With fields of:
username > varchar(50)
password > varchar(150);
salt > varchar(6);

If your lost already, then stop now and forget your project. Your not ready.

Register
Code:

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
//make the user confirm the pass word.
$cpass = mysql_real_escape_string($_POST['cpass']);

if(empty($username) || empty($password) || empty($cpass))
{
  //change here, to do more than just exit.
  exit;
}

if($cpass !== $password)
{
  //change here to do more than exit.
  exit;
}

//validate the username and password.
//check its length and make sure its not too short and not too long.
// maybe use a regex to make sure it doesn't contain any bad characters.

function createSalt()
{
   $string = md5(uniqid(rand(), true));
     return substr($string, 0, 6);
}
$salt = createSalt();
$p = hash('sha256', $salt . $password);
//password is now hashed and salted and secure.

//then insert the user into the database.
mysql_query('INSERT INTO your_users_table VALUES(\''.$username.'\',\''.$p.'\',\''.$salt.'\')');

That is the very basics of a registration script and there is a lot to fill in the gaps.
But the registration of each website will be unique, in terms of database, whats being stored, validation etc..

grimofdoom
grimofdoom
Member
Member
Forum Posts : 106
Member Since : 2012-03-06

Postgrimofdoom 8/4/2012, 3:49 pm

I got confused reading that,so i went and ended up finding phpacademy and started the first video on login. though i keep getting a T_STRING error on(it does have a closing)
Code:
mysql_select_db("a3197062_Users") or die("could not find db");




UPDATE:i foud the problem,forgot the ";" at the end of the last line before it
Sponsored content

PostSponsored content

View previous topic View next topic Back to top

Create an account or log in to leave a reply

You need to be a member in order to leave a reply.

Create an account

Join our community by creating a new account. It's easy!


Create a new account

Log in

Already have an account? No problem, log in here.


Log in

 
Permissions in this forum:
You cannot reply to topics in this forum