env3rt Posted September 30, 2007 Share Posted September 30, 2007 Hi i'm new to php and I'm just wondering if instead of putting: if(($_POST['password'] == PASSWORD) AND ($_POST['account'] == ACCOUNT) OR ($_POST['password'] == PASSWORD2) AND ($_POST['account'] == ACCOUNT2) OR ($_POST['password'] == PASSWORD3) AND ($_POST['account'] == ACCOUNT3)) Could I just put something more simple like one if statement that works for all the accounts? <?php session_start(); define('ACCOUNT', 'name1'); define('PASSWORD', 'password1'); define('ACCOUNT2', 'name2'); define('PASSWORD2', 'password2'); define('ACCOUNT3', 'name3'); define('PASSWORD3', 'password2'); if($_POST['check']) { if(($_POST['password'] == PASSWORD) AND ($_POST['account'] == ACCOUNT) OR ($_POST['password'] == PASSWORD2) AND ($_POST['account'] == ACCOUNT2) OR ($_POST['password'] == PASSWORD3) AND ($_POST['account'] == ACCOUNT3)) { echo " <body bgcolor='#757575'> Thanks $account, you're now logged in. "; } else { echo "Authencation failed."; die(" <body bgcolor='#757575'> <center> <form method='post' action='?'> Account: <input name='account' size='17' /> <br> Password: <input type='password' name='password' size='17' /> <input type='submit' value='Login!' name='check'> </form> </center> </body>"); } } else { die(" <body bgcolor='#757575'> <center> <form method='post' action='?'> Account: <input name='account' size='17' /> <br> Password: <input type='password' name='password' size='17' /> <input type='submit' value='Login!' name='check'> </form> </center> </body>"); } Link to comment https://forums.phpfreaks.com/topic/71266-need-help-with-simple-login/ Share on other sites More sharing options...
BlueSkyIS Posted September 30, 2007 Share Posted September 30, 2007 that IS one if statement. by the way, the way you're grouping ands/ors will not work as you expect it to. you need to rearrange your parentheses: if( ($_POST['password'] == PASSWORD AND $_POST['account'] == ACCOUNT) OR ($_POST['password'] == PASSWORD2 AND $_POST['account'] == ACCOUNT2) OR ($_POST['password'] == PASSWORD3 AND $_POST['account'] == ACCOUNT3) ) Link to comment https://forums.phpfreaks.com/topic/71266-need-help-with-simple-login/#findComment-358456 Share on other sites More sharing options...
env3rt Posted September 30, 2007 Author Share Posted September 30, 2007 Oh yes but is there a way to put some math into it or something to make it more simple, like if(($_POST['password'] == PASSWORD(all numbers) AND $_POST['account'] == ACCOUNT(all numbers)) but then I also only want each password to work with 1 account. Link to comment https://forums.phpfreaks.com/topic/71266-need-help-with-simple-login/#findComment-358460 Share on other sites More sharing options...
BlueSkyIS Posted September 30, 2007 Share Posted September 30, 2007 yes, but that is very insecure. you essentially give the user 3 x 3! different login possibilities. and you certainly don't save any white space. here is one way to do it: $good_passes = array($PASSWORD, $PASSWORD2, $PASSWORD3); $good_accounts = array($ACCOUNT, $ACCOUNT2, $ACCOUNT3); if (in_array($_POST['password'], $good_passes) && in_array($_POST['account'], $good_accounts)) { // User has correctly guessed one of the many possible accounts and passwords combinations. } Link to comment https://forums.phpfreaks.com/topic/71266-need-help-with-simple-login/#findComment-358463 Share on other sites More sharing options...
env3rt Posted September 30, 2007 Author Share Posted September 30, 2007 That works except I don't like the 3x3 thing. Is the way I'm doing it the only way you can do it without making it 3x3? Link to comment https://forums.phpfreaks.com/topic/71266-need-help-with-simple-login/#findComment-358468 Share on other sites More sharing options...
env3rt Posted September 30, 2007 Author Share Posted September 30, 2007 $good_passes = array($PASSWORD, $PASSWORD2, $PASSWORD3); $good_accounts = array($ACCOUNT, $ACCOUNT2, $ACCOUNT3); if (in_array($_POST['password'], $good_passes) && in_array($_POST['account'], $good_accounts)) { // User has correctly guessed one of the many possible accounts and passwords combinations. } Is a way of doing it but I don't want the 9 possible combinations I only want password2 to work with account2 etc.. Anybody have an idea? Link to comment https://forums.phpfreaks.com/topic/71266-need-help-with-simple-login/#findComment-358478 Share on other sites More sharing options...
BlueSkyIS Posted September 30, 2007 Share Posted September 30, 2007 yes, try this: if( ($_POST['password'] == PASSWORD AND $_POST['account'] == ACCOUNT) OR ($_POST['password'] == PASSWORD2 AND $_POST['account'] == ACCOUNT2) OR ($_POST['password'] == PASSWORD3 AND $_POST['account'] == ACCOUNT3) ) Link to comment https://forums.phpfreaks.com/topic/71266-need-help-with-simple-login/#findComment-358481 Share on other sites More sharing options...
env3rt Posted September 30, 2007 Author Share Posted September 30, 2007 That's too long but if that's the only way I suppose I'll settle for it. Link to comment https://forums.phpfreaks.com/topic/71266-need-help-with-simple-login/#findComment-358482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.