473,473 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Having problems with my php login script

Me
I made a login script which retrieves username and password from a database,
I can get it to work if the passwords in the database are not encrypted and
if I dont encrypt the password when it is entered, but if I encrypt the
password that has been entered and try to match with the encrypted one in
the database then it does not work, can anyone help me please, I have
included both the sources here.

Source with password not encrypted:

<?php
session_start();
require('db_connect.php');

$username = $_POST['username'];
$oldpass = $_POST['password'];

if(!$username) {
include 'login_nothing.php';
exit();
}

if(!$password) {
include 'login_nothing.php';
exit();
}
mysql_select_db('poweredge', $link);
$sql_query = mysql_query("SELECT * FROM users WHERE username = '$username'
AND password = '$oldpass'");

if(!$sql_query) {
echo "Fatal error";
exit();
}

$login_check = mysql_num_rows($sql_query);

echo "$login_check";

if($login_check == 0) {
include 'login_error.php';
exit();
}

if($login_check == 1) {

session_register('username');
session_register('password');
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("Location: memberspage.php");
}
?>

Source with password encrypted:

<?php
session_start();
require('db_connect.php');

$username = $_POST['username'];
$oldpass = $_POST['password'];

if(!$username) {
include 'login_nothing.php';
exit();
}

if(!$password) {
include 'login_nothing.php';
exit();
}

$password = md5($oldpass);

mysql_select_db('poweredge', $link);
$sql_query = mysql_query("SELECT * FROM users WHERE username = '$username'
AND password = '$password'");

if(!$sql_query) {
echo "Fatal error";
exit();
}

$login_check = mysql_num_rows($sql_query);

echo "$login_check";

if($login_check == 0) {
include 'login_error.php';
exit();
}

if($login_check == 1) {

session_register('username');
session_register('password');
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("Location: memberspage.php");
}
?>
Jul 17 '05 #1
2 3209
Me wrote:
I made a login script which retrieves username and password from a
database, I can get it to work if the passwords in the database are not
encrypted and if I dont encrypt the password when it is entered, but if I
encrypt the password that has been entered and try to match with the
encrypted one in the database then it does not work, can anyone help me
please, I have included both the sources here.

Source with password not encrypted:

<?php
session_start();
require('db_connect.php');

$username = $_POST['username'];
$oldpass = $_POST['password'];

if(!$username) {
include 'login_nothing.php';
exit();
}

if(!$password) {
include 'login_nothing.php';
exit();
}
mysql_select_db('poweredge', $link);
$sql_query = mysql_query("SELECT * FROM users WHERE username = '$username'
AND password = '$oldpass'");

if(!$sql_query) {
echo "Fatal error";
exit();
}

$login_check = mysql_num_rows($sql_query);

echo "$login_check";

if($login_check == 0) {
include 'login_error.php';
exit();
}

if($login_check == 1) {

session_register('username');
session_register('password');
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("Location: memberspage.php");
}
?>

Source with password encrypted:

<?php
session_start();
require('db_connect.php');

$username = $_POST['username'];
$oldpass = $_POST['password'];

if(!$username) {
include 'login_nothing.php';
exit();
}

if(!$password) {
include 'login_nothing.php';
exit();
}

$password = md5($oldpass);

mysql_select_db('poweredge', $link);
$sql_query = mysql_query("SELECT * FROM users WHERE username = '$username'
AND password = '$password'");

if(!$sql_query) {
echo "Fatal error";
exit();
}

$login_check = mysql_num_rows($sql_query);

echo "$login_check";

if($login_check == 0) {
include 'login_error.php';
exit();
}

if($login_check == 1) {

session_register('username');
session_register('password');
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

header("Location: memberspage.php");
}
?>

Saying "it does not work" doesn't really help, but I'll try anyways....when
you md5() the password that the user enters, have the passwords in the
database already been changed to md5 hashes?
Jul 17 '05 #2
Me wrote:
I made a login script which retrieves username and password from a
database, I can get it to work if the passwords in the database are not
encrypted and if I dont encrypt the password when it is entered, but if I
encrypt the password that has been entered and try to match with the
encrypted one in the database then it does not work, can anyone help me
please, I have included both the sources here.


The SQL when you insert a new user's password:
INSERT INTO users SET password=MD5('$password')

When you try to match passwords, where the user-entered password is in the
variable $pw:
SELECT * FROM users WHERE password=MD5('$pw')

In the same way, you can use the MySQL PASSWORD() function to encrypt
passwords.

..:Albe

--
http://www.ninja.up.ac.za
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Manu J | last post by:
Hi, i have a login script which makes use of sessions. Login script *********** session_start() ..... ..... ....
3
by: koolyio | last post by:
Hey, could you please tell me what is wrong with my login script. I just started learning php. CODE: login.php <? session_start(); header("Cache-Control: private"); ?>
9
by: Graham Campbell | last post by:
I have a login script to a website where a user logs in through a standard webform with a username and password that needs to be validated. My problem is that IE6 doesn't seem to pick up on valid...
4
by: Tamer Higazi | last post by:
Hi! I wrote a small script setting a cookie.... but nothing is being set. What could be the problem?! Did I make something wrong?! One script is used to ask for the cookie and the other one shows...
3
by: Justin Morris via DotNetMonster.com | last post by:
<asp:TextBox ID="TextBox1" runat="server" value='<%=Server.HtmlEncode (Request.Cookies("Username")("Username"))%>'/> <input name="Password" type="text" id="Password" value='<%...
2
by: Assimalyst | last post by:
Hi, I am creating a website where i want to allow some webforms to be accessible to all users, and those in a subdirectory available only to authenticated users. I have created a script to...
3
by: Lloyd Sheen | last post by:
I need to add a login front end to an existing website. No big deal ???? VS 2005 / Vista / II7 / SQL Express Well I go into the security and add a welcome page and a login page. Real easy...
0
by: kang jia | last post by:
hi i have small problems occurred in my login function, which i use Django to build, in my template which is login.html, the code is like the following: <html> <head>...
3
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.