I am working on a logon script for a web applicaton. I am trying to create a clause whereby if the correct username and password are entered proceed to the next page, but if a wrong username is entered give an error, or if the wrong password is entered give an error, and as that hasn't seemed to suffice, if a correct username but wrong password is entered give and error and visa versa.
Below is the code i have been testing, it works for all occurrances except where a correct username is entered with a wrong password or via versa, in this case i get an internal server error, instead of my own specified error.
#after reading in the values
if($username eq "" || $hashPassword == $null) {
error();
}else{
#after comparing them to the actual passwords stored in
$sth = $db->prepare(q{SELECT userid, password from user where userid =
+ ?})
or die("usr prepare error: $!");
$usr->execute($username)
or die("usr prepare error: $!");
while(@row = $sth->fetchrow_array){
if($username eq $row[0] && $hashPassword eq $row[1]) {
#Go to the new page
}elsif($username ne $row[0] || $hashPassword != $row[1]) {
error();
}elsif($username eq $row[0] && $hashPassword != $row[1]) {
error();
}elsif($username ne $row[0] && $hashPassword == $row[1]) {
error();
}elsif($username ne $row[0] && $hashPassword != $row[1]) {
error();
}
}
Can anybody see what I am doing wrong? Thanks
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|