Jump to content

[SOLVED] Little login system


FlyingIsFun1217

Recommended Posts

Hey!

 

Needing to create a little site frontend, I figured I'd come back and try PHP again.

 

Well, I've got my basic code done fairly well, but it doesn't work as expected.

 

Here's the code:

 

Index.html:

<html>
<head>
	<title>Simple PHP Gallery</title>
	<meta name="description" content="Simple image gallery using PHP" />
</head>
<body>
	<center>
	<h1>Simple PHP Gallery</h1>
	</center>

	<form>
		<fieldset>
			<form action="loginCheck.php" method="post"/>
				<center>
					<p>
						<b>Password:</b>
						<input type="password" name="passwrd"/>
					</p>
				</center>

				<center>
					<input type="submit" value="View Gallery"/>
				</center>
			</form>
		</fieldset>
	</form>

</body>
</html>

 

loginCheck.php:

<?php
$passwordFromLogin = $_POST['passwrd'];
$passwordEncrypted = md5($passwordFromLogin);
$passwordCheck = "false";

include("passWrd.php");

if ($passwordEncrypted == $currentPassword)
	header('anjgnwerg.php');
else
	header('error.html');
?>

 

passWrd.php:

<?php
$currentPassword = 'thisisthepassword';
?>

 

Now, after entering in a bogus password, I would expect to get my error page, but that's not the case.

 

An example can be found here.

 

Thanks!

FlyingIsFun1217

Link to comment
Share on other sites

You do realize md5 makes a hash of the incoming password, right?

 

you would have to include the md5 hash, not the actual password in passWrd.php

 

$currentPassword = 'thisisthepassword'; would be wrong.

 

$currentPassword = 'd9ec646d4a782cfbc7f6cdbad62993d1'; would == the md5 of 'thisisthepassword'.

 

Little vague on what's really happening though.

 

Also, why are you using header()? Just include it.

Link to comment
Share on other sites

I know it creates an MD5 hash, that's why I want to use it. Eventually, I'd like to store the MD5 hash of the password, and then check it against the hash of the password entered in the passwrd box. Right now, I want to just make sure that it forwards through the pages like I want it to, so I purposely left the passwrd box as it is, instead of getting it's hash.

 

Essentially, what I want to do is get the password from the box, check to see if it's the same value as that stored in currentPassword, and proceed if it checked in the same (or regress if it didn't). Sorry if my methods are not clear, I'm used to coding with C++, a more object-oriented approach :/

 

Thanks again!

FlyingIsFun1217

Link to comment
Share on other sites

As awpti said, md5 creates a hash of the incoming value. You're creating a hash of the password, then checking it to see if it's the same as a conjunction of english words.. not gunna happen.

 

Try un-hashing the password until you've checked to see if it's the same as the $currentPassword.

 

--

DJ

Link to comment
Share on other sites

So comparing the hash to the current password is like comparing an int with a char in C++? I think I'm getting it.

 

I'll use the MD5 hash you posted above, and see if it doesn't work.

 

Thanks!

FlyingIsFun1217

 

----------EDIT----------

Tried using the hash, I still get the same results with a wrong password entered. Shouldn't it be going to error.html? Why isn't it, that's my biggest problem right now... :/

 

Thanks again!

FlyingIsFun1217

Link to comment
Share on other sites

login.php

 

<?
$include("password.php");

$password = $_POST['password'];
$encpass = md5($password);

if($encpass == $real_pass){
header("Location: home.html");
}
else{
header("Location:error.html");
}
?>

 

password.php

 

<?
$passwordywordthing == "password!1";
$real_pass == md5($passwordywordthing);
?>

 

Should work just dandy, you should md5() your real password and failing this just use Javascript :P

 

 

Link to comment
Share on other sites

Here's my current code (still failing as before):

 

Index.html:

<html>
<head>
	<title>Simple PHP Gallery</title>
	<meta name="description" content="Simple image gallery using PHP" />
</head>
<body>
	<center>
	<h1>Simple PHP Gallery</h1>
	</center>

	<form>
		<fieldset>
			<form action="loginCheck.php" method="post"/>
				<center>
					<p>
						<b>Password:</b>
						<input type="password" name="passwrd"/>
					</p>
				</center>

				<center>
					<input type="submit" value="View Gallery"/>
				</center>
			</form>
		</fieldset>
	</form>

</body>
</html>

 

loginCheck.php:

<?php
include("passWrd.php");

$passwordFromLogin = $_POST['passwrd'];
$passwordEncrypted = md5($passwordFromLogin);

if ($passwordEncrypted == $encryptedPass)
{
	header("correctLogin.php");
}
else
{
	header("error.html");
}
?>

 

passWrd.php:

<?php
$passwordText = "samplepassword";
$encryptedPass = md5($passwordText);
?>

 

Maybe it's failing because of header() being in the html body? Is there another way to forward through the pages?

 

Thanks again!

FlyingIsFun1217

Link to comment
Share on other sites

Try this :).it should work

<?php

$passwordText = "samplepassword";
$encryptedPass = md5($passwordText);

$passwordFromLogin = $_POST['passwrd'];
$passwordEncrypted = md5($passwordFromLogin);

echo "Your pass :$encryptedPass<BR>Entered pass:$passwordEncrypted"; //Remove this line when ur done testing
if ($passwordEncrypted == $encryptedPass)
{
	header("Location: http://" . $_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF'])."/correctLogin.php");

}
else
{
	header("Location: http://" . $_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF'])."/error.html");
}
?>

Link to comment
Share on other sites

Seems all I really needed to do was check my index. I had a form directly under a form (<form><form blahblah></form></form>). I think this was the case, anyway.

 

Either way, it's working now.

 

Thanks for everybody who took the time to help me. Now I'm dealing with image stuff...

 

FlyingIsFun1217

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.