Jump to content

login.php

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
gwopboi

gwopboi

    Newbie

  • Members
  • Pip
  • 6 posts
what's up, im quite new to this so wondering if you guys can help me out.

i was wondering how do i use php to check that a username and password are correct?

i was thinking about using this $checkusername = strpos($username, $login);
but dont know how to progress from there


thanks :)

Edited by gwopboi, 27 March 2010 - 07:41 AM.


#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
you only need to check if the password(and username if you want but that's not necessary) is the same as what it should be, if so you can print out the page or else show an error. Do you have any code so far?

#3
gwopboi

gwopboi

    Newbie

  • Members
  • Pip
  • 6 posts
he is the code i've got so far:

PHP:
<?php

$password = "test"; 

$pass= $_POST["pass"];

$checkpassword = strpos ($password, $pass);


if ($checkpassword === TRUE) {

    echo  "correct password"; }

    

else {

   

}

?>




it says wrong password when i run it..(btw just wrote 'correct password' there now just to chck but if correct i want it to go to another page, not to sure how to do that yet)

so basically i want it to check both password and user and if correct redirect to another page


thanks again!

Edited by gwopboi, 27 March 2010 - 07:42 AM.


#4
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
why aren't you just doing:

if ($password == $pass)


#5
gwopboi

gwopboi

    Newbie

  • Members
  • Pip
  • 6 posts
oh... didnt even see that.
thanks

Edited by gwopboi, 27 March 2010 - 07:42 AM.


#6
brokenbylaw

brokenbylaw

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
Why don't you just check if the password is equal?

if ($_POST['pass'] == "1234" && $_POST['user'] == "admin"){

}else{

}


#7
brokenbylaw

brokenbylaw

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
Didn't notice that last reply, check all your variables, make sure everything is all dandy and clean

without the code i can't really help :p

#8
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Your PHP code doesn't even seem to have 15 lines, can you post your current PHP code.

#9
gwopboi

gwopboi

    Newbie

  • Members
  • Pip
  • 6 posts
yes! thanks that did the trick!

#10
brokenbylaw

brokenbylaw

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
you think about beefing up your security? try the hash function

[COLOR=#000000][COLOR=#007700][/COLOR][COLOR=#0000BB]hash[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'whirlpool'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'The quick brown fox jumped over the lazy dog.'[/COLOR][COLOR=#007700]);[/COLOR][/COLOR]
you can use ripemd5, whirlpool, md5, sha512 look at the php docs for a complete list :)

PHP: hash - Manual

#11
gwopboi

gwopboi

    Newbie

  • Members
  • Pip
  • 6 posts
now it works, so if the IF statement is true and i want to redirect to another page ...how will i go about doing it?

Edited by gwopboi, 27 March 2010 - 07:43 AM.


#12
brokenbylaw

brokenbylaw

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
redirect in php would be through the header function

header('location:http://www.google.com');