PDA

View Full Version : login script



Mole
October 23rd, 2006, 17:33
Can someone make me a login script? I tried searching for one but they either require alot of script editing. I need one that you can put different login users and passwords but no registering form.

krakjoe
October 23rd, 2006, 18:11
a login script to what ?

Mole
October 23rd, 2006, 18:19
for a members page I made. I need it so when the put in the password and username i give them it will send them to my member's page.

Mole
October 23rd, 2006, 18:41
the only ones i can find displays the password and username in the source

Abush
October 23rd, 2006, 19:13
A bit more info would be helpfull. What databases are you trying to use? What language you want it in? details...details...details.

Darko
October 23rd, 2006, 20:43
yeah, you should explain more. but i can help you, contact me at darko-inc at hotmail.com

brutetal
October 23rd, 2006, 23:49
I can give u a basic one, in php and requires a mysql table.

Mole
October 23rd, 2006, 23:53
Sorry i need one that does php and use mysql table. English Only and i need it for my members Section.

Mole
October 24th, 2006, 00:29
i sent you a email Darko

Fried
October 24th, 2006, 04:01
Ok try this. It doesn't use a mySQL table.

login.html

<form action="members.php" method="post">
Username: <input type="text" name="userid"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" value="Login">
</form>

members.php

<?php
$userid = $_GET['userid'];
$pass = $_GET['pass'];

if($userid == "USERNAME1"){ if($pass == "PASSWORD1"){ $bad = false; } }
if($userid == "USERNAME2"){ if($pass == "PASSWORD2"){ $bad = false; } }
if($userid == "USERNAME3"){ if($pass == "PASSWORD3"){ $bad = false; } }
if($userid == "USERNAME4"){ if($pass == "PASSWORD4"){ $bad = false; } }
if($userid == "USERNAME5"){ if($pass == "PASSWORD5"){ $bad = false; } }
if($userid == "USERNAME6"){ if($pass == "PASSWORD6"){ $bad = false; } }

if(! $bad){
die("Invalid Username and Password.");
}
?>

HTML code for members page goes here


I havn't tested it but it should work.

krakjoe
October 24th, 2006, 04:05
I'm still not so sure about what you're trying to achieve here, you said you want them to be able to log into a members page ? and what sort of things you would like them to be able to do once they are there ?

Darko
October 24th, 2006, 04:15
he wants a membership system, where only the admin, can add new members, but still not sure what he wants the members to do, i emailed him, i like what you did Gopzap, but might wanna add md5 to it, for security reasons

krakjoe
October 24th, 2006, 04:44
here's how I would achieve something real basic like that, without being insecure ....

my members.php would look like



<?php session_start();

if ($_GET['action'] == "logout")
{
session_destroy();
header("location: members.php");
exit;
}

$users = parse_ini_file("users.ini", TRUE);

$name = $_POST['userid'];

if (!$_SESSION['authed'])
{
if (isset($users[$name]) && $users[$name]["password"] == $_POST['pass'])
{
$_SESSION['authed'] = true;
$_SESSION['user'] = $_POST['userid'];
header("location: members.php");
exit;
}
else {
header("location: login.php");
exit;
}
}
else
{ // PROTECTED CONTENT
?>
Hi <?=$_SESSION['user'];?>, welcome to the members section<br>
<a href="?action=logout">Logout</a>
<?
} // END PROTECTED CONTENT
?>


I would then store user info in an ini file ( if I couldn't use a database ), it would look like :



; Sample Users file

[joe]
password = passphrase
age = 21
location = uk

[fred]
password = pass
age = 22
location = uk


I would keep it under my webroot, somewhere php can read and write .....and I used his login form ...... the advantages are that I use session which is far superiour to loggin in using post, and you can store info for longer ..... anyway, that's what I would do ....

Fried
October 24th, 2006, 05:34
Well yeah you can use krak_joe's script if your member page is more than one page - As it has sessions.

Mole
October 24th, 2006, 08:57
the members page is one page with links on it to special webmaster codes that the people I Host can use. krak_joe will yours use MySQL?

krakjoe
October 24th, 2006, 09:01
I can make it use sql, if you wanted ..... what do you need exactly ? make me a list of bullet points and I'll tell ya what I think ....

Mole
October 24th, 2006, 09:02
what you mean bullet points?

krakjoe
October 24th, 2006, 09:06
like a list of things that you need this page to do, and what forum software you want to use for authentication

Mole
October 24th, 2006, 09:09
I will be sending there username and password to login to it when they register for a hosting account with me. I nedd the login script to be fixed were I can add unlimited amount of usernames and passwords. The Member's Pages will have my webmaster Codes and probley a News Area.

krakjoe
October 24th, 2006, 09:14
so will all the people that have access to your server be using this page ? if so, I could use authentication straight from cpanel without the need for any sql at all .....and if I just protect a page and you can design it ?

Mole
October 24th, 2006, 09:15
yes I will design the page and they all will login to the same page.

krakjoe
October 24th, 2006, 09:16
so I'll use cpanel to protect it then yeah ? without a database ?

Mole
October 24th, 2006, 09:19
that will work.

Mole
October 24th, 2006, 09:24
not exactly i seen a simler script that didnt have to scan but it displayed the username and password in the soruce code

Fried
October 24th, 2006, 09:25
Wtf? Where's my post gone... Well anyway then that's probably going to use WHM Accesshash.

Mole
October 24th, 2006, 09:26
no because it doesnt use WHM access it just logins it has no access to cpanel nor WHM when the login they go to the members area not WHM or cpanel

Fried
October 24th, 2006, 09:30
no because it doesnt use WHM access it just logins it has no access to cpanel nor WHM when the login they go to the members area not WHM or cpanel
Then that's exactly what I said in my deleted post. It will connect to port :2082 using sockets, check if the username and password is invalid or not, and return the value. And it doesn't need your WHM Accesshash, because it's not going to use cPanel accounting module.

Mole
October 24th, 2006, 09:32
all it does is when you login with the username and password (Not the same as there cpanel login details.) it will go the the member's area.

krakjoe
October 24th, 2006, 09:34
so I made a protected page that uses cpanel to autheticate the user, so you don't need to create users for it, they are created when thier account is, will that do ?

Fried
October 24th, 2006, 09:34
all it does is when you login with the username and password (Not the same as there cpanel login details.) it will go the the member's area.
Oh sorry, I misunderstood.
But that's what krak_joe is making you right now, a script that will check if their cPanel login details are correct and return the values...

Mole
October 24th, 2006, 09:37
well...yea that can work..thats even better

krakjoe
October 24th, 2006, 09:46
ok, so ......

login.php



<?php session_start();

// FUNCTION TO AUTHORIZE A USER WITH CPANEL LOGIN DETAILS
function auth()
{
if (empty($_POST['user']) || empty($_POST['pass']))
{
header("location: login.php");
exit;
}
if ( strlen($_POST['user']) > 8 )
{
header("location: login.php");
exit;
}
$url = "http://".$_POST['user'].":".$_POST['pass']."@localhost:2082/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (!preg_match("/cPanel Login/i", $result))
{ // if
$_SESSION['user'] = $_POST['user'];
$_SESSION['authed'] = true;
return true;
}
else // else
{
return false;
}
} // end if
// END FUNCTION TO AUTHORIZE A USER WITH CPANEL LOGIN DETAILS

if (!$_POST)
{ // THIS CAN BE REPLACED WITH YOUR OWN HTML
// ENSURE YOU GIVE THE FORM OBJECTS THE SAME NAMES
echo "<form action=\"\" method=\"post\">\n";
echo "Username :&nbsp;<input type=\"text\" name=\"user\"><br>\n";
echo "Password :&nbsp;<input type=\"password\" name=\"pass\"><br>\n";
echo "<input type=\"submit\" value=\"login\"><br>\n";
echo "</form>";
exit;
}
elseif (auth()) {
header("location: members.php");
exit;
}
else
{
header("location members.php");
exit;
} // end if
?>


and members.php, the page that is protected ....



<?php session_start();
// Make sure the user has permissions to view the page
if (!$_SESSION['authed']) { header("location: login.php"); exit; }

// Logout
if ($_GET['action'] == "logout")
{
session_destroy();
header("location: login.php");
}
?>
<!-- PROTECTED PAGE -->
<a href="?action=logout">Logout</a>


You don't need to do anything at all, the persons username is stored in $_SESSION['user'] passwords are not, as that's insecure, but you can greet by name.

or you want it to use sql ?

Mole
October 24th, 2006, 09:49
no that can work..ty ty ty

krakjoe
October 24th, 2006, 09:50
sure anytime .... don't forget to backup your account ( self promotion is everything )

Mole
October 24th, 2006, 09:58
that works perfectly..great job on the script

krakjoe
October 24th, 2006, 10:17
:drink: the beers are on you ......

Mole
October 24th, 2006, 12:18
the script does great and was easy to install. ty for the great job.

Boby
October 27th, 2006, 08:10
Hello Mole,

If you need in ASP just go through this :-) http://www.evolt.org/node/28652

krakjoe
October 27th, 2006, 10:35
why would you need a cpanel login script in asp ?