Simple Machines Community Forum

Archived Boards and Threads... => Archived Boards => Parham's PHP Tutorials => Topic started by: Alan S on August 06, 2006, 11:31:01 AM

Title: Php Question
Post by: Alan S on August 06, 2006, 11:31:01 AM
I have a simple php pass protect page script

<?php

// Define your username and password
$username = "smithalan2";
$password = "theteenzone";


if (
$_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password ) {

?>



but i want to have 2 usernames and 2 passwords , im not sure what code to edit though , im guessing i'd add another variable like $username2 = " ***"; or something but im not sure what i'd add on line if ($_POST['txt................etc?

Help Would be appreciated
Title: Re: Php Question
Post by: Alan S on August 07, 2006, 04:00:29 PM
Anyone?? this is the actual whole code

<?php

// Define your username and password
$username = "smithalan2";
$password = "theteenzone";


if (
$_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password ) {

?>

<h1>Login</h1>

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <p><label for="txtUsername">Username:</label>
    <br /><input type="text" title="Enter your Username" name="txtUsername" /></p>

    <p><label for="txtpassword">Password:</label>
    <br /><input type="password" title="Enter your password" name="txtPassword" /></p>

    <p><input type="submit" name="Submit" value="Login" /></p>

</form>

<?php

}
else {

?>

<p><font color="white">No Staff News Yet But Check Back Soon For More Details!</font></p>

<?php

}

?>
Title: Re: Php Question
Post by: Alan S on August 09, 2006, 11:43:20 AM
emm *bump*      anyone?????
Title: Re: Php Question
Post by: SleePy on August 09, 2006, 02:26:28 PM
thats one messed up script.
should be like this:

if ($_POST['txtUsername'] == $username && $_POST['txtPassword'] == $password ) {

That says if username and password are correct it will display your page. otherwise give them a login screen. maybe and error 2.
then you can double it up easy

if (($_POST['txtUsername'] == $username && $_POST['txtPassword'] == $password ) || ($_POST['txtUsername'] == $username2 && $_POST['txtPassword'] == $password2 )) {

Im glad you disabled it agaisn't url insertion. but i would take it a step further.
md5 your password to add some security on it. maybe your name to if you want. could use some other encryption as well like adding your site name in and such.

just create a php page with a simple md5 in it
<?
echo md5($_GET['a']);
?>

do a=yourpassword in url and it will give md5 of the password. put it in place of our password

then change this password part in your if statement
$txtPassword = md5($_POST['txtPassword']);
Title: Re: Php Question
Post by: JayBachatero on September 14, 2006, 10:27:47 AM
Why not just link it to SMF?
Title: Re: Php Question
Post by: Alan S on September 15, 2006, 02:53:55 AM
That was just a little script i was playing around on a html/php website.
Title: Re: Php Question
Post by: Rudolf on September 15, 2006, 03:22:01 AM
How's this?

<?php

// Define your username and password
$usernames = array("username1",'username2','username3');
$passwords = array('password1','password2','password3');

$key = array_search($_POST['txtUsername'],$usernames);
if (
$key === false && array_search($_POST['txtPassword'],$passwords) !=$key) {

?>


You can have as many username-password pair you wish.
Title: Re: Php Question
Post by: Alan S on September 15, 2006, 10:02:28 AM
Thanks ! , i wasnt actually planning on using it on a template at the moment but im getting a idea of something i'll be able to use it in!