Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> A Simple Password Page, I can't make one!!!
tricky77puzzle
post Mar 4 2008, 03:08 AM
Post #1


Super Member
*********

Group: [HOSTED]
Posts: 416
Joined: 26-January 08
Member No.: 56,881



I'm trying to make a simple password page for one of my PHP experiments. Every time I try to post a password, however, it returns an error that the connection was "closed by the server".

The entire code is only 3 pages.

password.php:

CODE
<?php

$rightuser = "";
$rightpass = "";

include ('getpassword.php');

if $_POST['user'] !== $rightuser
{ if $rightuser == ''
{
?>The username is incorrect. It should be blank.<?php ;
}
else
{
?>The username is incorrect. It should be .<?php ;
}
}
else
{ if $_POST['pass'] !== $rightpass
{ if $rightpass == ''
{
?>The password is incorrect. It should be blank.<?php ;
}
else
{
?>The password is incorrect. It should be<?php echo $rightpass;
}
}
else
{ ?>The password is correct.'; }<?php
}
?>


getpassword.php:

CODE
<?php

$rightuser = "";
$rightpass = "1234567890";

?>


password.html:

CODE
<html>
<head>
</head>
<body>

<form action="password.php">
<p>Username: <input type="text" name="user" /></p>
<p>Password: <input type="text" name="pass" /></p>
<p><input type="submit" value="Submit" /></p>
</form>

</body>


What am I doing wrong? Help is greatly appreciated...
Go to the top of the page
 
+Quote Post
t3jem
post Mar 4 2008, 03:20 AM
Post #2


Privileged Member
*********

Group: [HOSTED]
Posts: 521
Joined: 9-February 07
Member No.: 38,519



QUOTE(tricky77puzzle @ Mar 3 2008, 08:08 PM) *
password.php:

CODE
<?php

$rightuser = "";
$rightpass = "";

include ('getpassword.php');

if $_POST['user'] !== $rightuser
{ if $rightuser == ''
{
?>The username is incorrect. It should be blank.<?php ;
}
else
{
?>The username is incorrect. It should be .<?php ;
}
}
else
{ if $_POST['pass'] !== $rightpass
{ if $rightpass == ''
{
?>The password is incorrect. It should be blank.<?php ;
}
else
{
?>The password is incorrect. It should be<?php echo $rightpass;
}
}
else
{ ?>The password is correct.'; }<?php
}
?>


getpassword.php:


password.html:

CODE
<html>
<head>
</head>
<body>

<form action="password.php">
<p>Username: <input type="text" name="user" /></p>
<p>Password: <input type="text" name="pass" /></p>
<p><input type="submit" value="Submit" /></p>
</form>

</body>


Alright, you have errors in these two pieces of code.

In the first, your if statements aren't typed right. Instead of "!==" it needs to be "!=".

An if statement also goes in the format if(*argument*){do something}else{do something}. For example

CODE
if($password == 'hi')
{
.. wrong password..
}
else
{
    if($password != 'hi') //does the same as an else just showing the not equal operator
    {
        right password
    }
}


The next error comes in your form, but it's an easy mistake. Just fix the form tag to " <form action='password.php' method='post'>".
This will post your data to your password.php file so that the php code can retrieve the data.

Hope this helps
Go to the top of the page
 
+Quote Post
jlhaslip
post Mar 4 2008, 04:48 AM
Post #3


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,882
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



A single page will do that for you...

CODE
<?php

$rightuser = "me";
$rightpass = "123";

if ( isset($_POST['user']) ) {
        if ( $rightpass == $_POST['pass'] ) {
                 echo '<p style=" color:green; ">Good Password</p>';
         }
        else {   /* password condition else */
                echo '<p style=" color:red; ">Bad Password</p>';
                }   /* password condition end */
        if ( $rightuser == $_POST['user'] ) {
                 echo '<p style=" color:green; ">Good Username</p>';
         }
        else {   /* user condition else */
                echo '<p style=" color:red; ">Bad Username</p>';
            
                 }   /* user condition end */
}     /* main condition end */
?>

<html>
<head>
</head>
<body>

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<p>Username: <input type="text" name="user" value="<?php if ( isset($_POST['user']) ) { echo $_POST['user']; } ?>" /></p>
<p>Password: <input type="text" name="pass" value="<?php if ( isset($_POST['pass']) ) { echo $_POST['pass']; } ?>" /></p>
<p><input type="submit" value="Submit" /></p>
</form>

</body>
</html>

Change the password and user as you need to, or add them into another file and include() them like your example code and delete them from this file. That might be better since it would save you having to edit the file containing the code itself. Less chance of messing it up.

Also, there is no Data checking in this script and you should at least add an function to convert the html entities to avoid someone goofing around with the page. I'll leave the level of data-checking to you. PM me if you need a function to do that. I have a couple different ones that I could show you.
Go to the top of the page
 
+Quote Post
tricky77puzzle
post Mar 4 2008, 10:45 PM
Post #4


Super Member
*********

Group: [HOSTED]
Posts: 416
Joined: 26-January 08
Member No.: 56,881



Okay, thanks, I got it. Thanks for your help.

BTW, I caught another error, which was that I forgot to put another close-brace at the end of the entire expression. laugh.gif

Now, I'm going to try using MySQL and seeing where that leads me.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Password Strength / User Availablity Scripts ?(2)
  2. Phpbb Password Protector(3)
  3. Registration Form?!(6)
  4. Gahhh This Isn't Going Well Please Help!(12)


 



- Lo-Fi Version Time is now: 26th July 2008 - 04:39 PM