0

hi I am using following code to validate username and password please can any body check where is the mistake...

$adminuser = $_POST['adminuser'];
$adminpass=$_POST['adminpass'];


if((!$adminuser=="") or (!$adminpass=="")){
	echo "Please enter Username and Password";
}
elseif((!$adminuser=="admin") or (!$adminpass=="manoj")){
	echo "Invalid Username and Password";
}
else{
	"good";
}

Edited by nav33n: Please use [code][/code] tags to wrap your code for easy readability.

6
Contributors
14
Replies
15
Views
7 Years
Discussion Span
Last Post by harshbavaliya
0

Please wrap code in [code]

[/code] tags code highlighting makes simple errors, obvious errors

<?php 
$adminuser = $_POST['adminuser'];
$adminpass=$_POST['adminpass'];
if((!$adminuser=="") or (!$adminpass=="")){
echo "Please enter Username and Password";
}
elseif((!$adminuser=="admin") or (!$adminpass=="manoj")){
echo "Invalid Username and Password";
}
else{ "good"; } ?>

try

<?php 
$adminuser = $_POST['adminuser'];
$adminpass = $_POST['adminpass'];
if((!$adminuser) or (!$adminpass)){ echo "Please enter Username and Password"; }
elseif(($adminuser=="admin") and ($adminpass=="manoj")){ echo "good"; }
else { echo "Invalid Username and/or Password";  }  ?>

Edited by almostbob: n/a

-1

almostbob, I think we must try to use && instead of and,

anyways, i think we can also use this code...

<?php
$adminuser = $_POST['adminuser'];
$adminpass=$_POST['adminpass'];

if(($adminuser || $adminpass)==NULL){ echo "Please enter Username and Password";}
else if(($adminuser=="admin") && ($adminpass=="manoj")){echo "Good!";}
else{echo "Invalid Username and Password";}
?>
0
this code detect the empty field.

      if(!$adminuser|| strlen($adminuser= trim($adminuser)) == 0){
      echo "empty value";
      }
-1

why can't you try it like this....

if(($_POST['adminuser']=="") || ($_POST['adminpass']=="")){
	echo "Please enter Username and Password";
}
elseif(($_POST['adminuser']!="admin") || ($_POST['adminpass']!="manoj")){
	echo "Invalid Username and Password";
}
else{
	"good";
}

Edited by saiprem: n/a

0

what is the difference between your and my logic ? I just I just passed the value of $_POST to $adminuser and $_POST to adminpass nothing much...

and I have done that because, I think by this we can save coding time... you just say that, which will be good for a coder?

$_POST['adminpass']

or

$adminpass

hummmm ?

-1

and saiprem,
just check your line no. 5, you have used || for checking that the username and password matches each other or not... just check it...

elseif(($_POST['adminuser']!="admin") || ($_POST['adminpass']!="manoj"))

Well I can bet that i can sing in if i only know password OR id... anyways you have a great idea for coding... lolz ;)

Edited by harshbavaliya: code mistake

0

and saiprem,
just check your line no. 5, you have used || for checking that the username and password matches each other or not... just check it...

elseif(($_POST['adminuser']!="admin") || ($_POST['adminpass']!="manoj"))

Well I can bet that i can sing in if i only know password OR id... anyways you have a great idea for coding... lolz ;)

I don't think there will be no difference between (or) or ||
So I used it, and I want to know that, have you tried executing the code which I given in the post(Sorry I haven't experimented it), I hope it should work, If not I am wrong in my post.

0

No saiprem,

I have not tried to run your code. But I can clearly see that there will be a logical error... on above line... we must use && or and for the condition... otherwise it will only check either id or password is correct or not...

0

why can't you try it like this....

if(($_POST['adminuser']=="") || ($_POST['adminpass']=="")){
	echo "Please enter Username and Password";
}

hey....harsha is right. here we can use "and" operation. . but your condition
is not work here. for example i am entering adminuser field and not entering password now i am submitting the form then the above condition checks now the condition is false. it will goes to else part. look at that code once.

Edited by muralikalpana: n/a

0

muralikalpana thanks for understanding me... do you know what is the main problem in this code?

lseif(($_POST['adminuser']!="admin") || ($_POST['adminpass']!="manoj")){
	echo "Invalid Username and Password";
}

This will require only one condition to be true out of two... If you enter "admin" as user id, and "harsh" as password then the condition will be true... and if you enter "harsh" as user id and "manoj" as password, then also the condition will be true...

Have a nice day.. :)

0

muralikalpana thanks for understanding me... do you know what is the main problem in this code?

lseif(($_POST['adminuser']!="admin") || ($_POST['adminpass']!="manoj")){
	echo "Invalid Username and Password";
}

This will require only one condition to be true out of two... If you enter "admin" as user id, and "harsh" as password then the condition will be true... and if you enter "harsh" as user id and "manoj" as password, then also the condition will be true...

Have a nice day.. :)

yes..you are absolutly correct.

0

hey....harsha is right. here we can use "and" operation. . but your condition
is not work here. for example i am entering adminuser field and not entering password now i am submitting the form then the above condition checks now the condition is false. it will goes to else part. look at that code once.

Yes I agree with that, the earlier code was with or, so I kept the same in LOGICAL NOTATION and used $_POST for checking.

0

saiprem,

Dear, we are here to learn and teach something, not to lose or win anything... am i right ?

Anyways i am leaving this thread from now... Sorry if I have done any mistakes in my past posts, and i had a question, this thread was clearly solved at second and third post, then why still this thread is not marked as solved...? anyways I learned so many things in this thread, even luckily I got a down vote also...

Okey then Bye... :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.