Jump to content


Photo

login script using php..no need database...


  • Please log in to reply
2 replies to this topic

#1 chowwiie

chowwiie
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 12 August 2006 - 05:28 AM

hi... is it possible for me to create a login script using php without the need of a database? im kinda new in this business and i want to learn more... can somebody help me... please... or better give me an example.. tnx:D

#2 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 12 August 2006 - 08:26 AM

It is not safe.

I am not gonna make the script as its unsafe, i 1ce hd such a script.
Ill just give the script to u, wait

EDIT:
Here
I consider that you already have a directory login setup
and your domain is http://localhost
so your login pages are at http://localhost/login/
now
1. Create a directory users in the login directory.

2. Here is your register script

Register.html
<html>
<head><title>Register</title></head>
<body>
<b>Register</b>
<br>
<form action="Register.php" method="post">
Username: <input type="text" name="un"><br>
Password: <input type="password" name="ps"><br>
Re-type Password: <input type="password" name="rps"><br>
<input type="submit" value="Register"><br>
</form>
</body>
</html>

3. Here is register page
Register.php
<html><head><title>Register</title></head>
<?php
$un=$_POST['un'];
$ps=$_POST['ps'];
$rps=$_POST['rps'];
if($ps==$rps)
{
echo("<font color=blue>Password matched! </font> you may continue!<br>");
if(file_exists("users/kaddu".$un."ismypass.bmp"))
{
echo("<font color=red>Sorry but the username already exits</font>");
exit();
}
else
{
$ps = sha1(md5($ps));
}
echo("<font color=blue>Adding your username and password to database</font>");
$users = "users/kaddu".$un."ismypass.bmp";
$ousers = fopen( $users, "a+" );
fwrite( $ousers, $ps );
fclose( $ousers );
}
}
else
{
echo("<font color=red>Password does not match </font> Please return and retype the password correctly!");
exit();
}
?>
</html>

4. Now lets create a login script.
Login.html
<html>
<head><title>Login</title></head>
<body>
<b>Login</b>
<br>
<form action="Login.php" method="post">
Username: <input type="text" name="un"><br>
Password: <input type="password" name="ps"><br>
<input type="submit" value="Login"><br>
</form>
</body>

5. To login we need login.php
Login.php
<html><head><title>Login</title></head>
<?php
$un=$_POST['un'];
$ps=$_POST['ps'];
if(file_exists("users/kaddu".$un."ismypass.bmp"))
{
$ps = sha1(md5($ps));
$users = "users/kaddu".$un."ismypass.bmp";
$ousers = fopen( $users, "a+" );
$size = filesize($users);
$ps2=fread( $ousers, $size );
fclose( $ousers );
if($ps==$ps2)
{
echo("You are now logged in");
}
else
{
echo("<font color=red>Wrong Password!</font>");
}
}
else 
{
echo("<font color=red>Wrong Username!</font>");
}
?>
</html>

Its not safe and you would have to code a lot even after you have done this to check weather someone is logged in or not, best thing to do is to use cookies after this
I am a PHP Guru, ask me questions if you want to

#3 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 12 August 2006 - 08:30 AM

I see you are a really new person at this and so you must understand that using MySQL would be better for you.
and this is just an example of creatting a really secure login without using DBs, which is indeed not as secure.
I am a PHP Guru, ask me questions if you want to




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users