This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-01-22 05:55:27

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Password protected pages.

I made a password protected page script in PHP, which is actually embedded in the .php file you want to put a password on. I actually made this for a friend just a while ago and decided to share it with everyone that doesn't know how to do it.

Code:

<?php
    //You can change this password to anything you want... If you want double quotes in your password, You need to escape them like this: \"
    $password = "macbookpro";

    $enteredPass = $_POST["password"];
    if (!($enteredPass == $password))
    {
        die('<div style="text-align: center;"><p>This page is protected with a password!</p><form name="input" action="' . $_SERVER['PHP_SELF']. '" method="POST">Password: <input type="password" name="password"><input type="submit" value="Submit"></form></div>');
    }

// Anything after this line will only be shown if the password is entered! ?>

<!DOCTYPE html>
<html>
    <head>
        <title>Protected page test</title>
    </head>
    <body>
        <p>This text will only appear after the password has been entered!</p>
    </body>
</html>

That is the complete file. Just save it in a file with the .php file extension.

Feel free to change this any way you want!


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#2 2013-01-22 07:22:43

BlackKyurem
Scratcher
Registered: 2012-12-22
Posts: 100+

Re: Password protected pages.

I might use that sometime if I actually consider learning php


inspirational quote as of now: anything you can imagine is real | Main Account: ProgrammingPro01
http://img843.imageshack.us/img843/1205/blackkyuremsig.png

Offline

 

#3 2013-01-22 09:01:04

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Password protected pages.

If you want to make it so that people can't find the password by looking at the file source (say they get on your computer), so hash the input, and put the hash in the code instead of the password.

Offline

 

#4 2013-01-22 10:42:47

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: Password protected pages.

shouldn't

Code:

(!($enteredPass == $password))

be

Code:

($enteredPass!=$password)

that's what i always thought


Why

Offline

 

#5 2013-01-22 10:44:39

muppetds
Scratcher
Registered: 2011-02-11
Posts: 1000+

Re: Password protected pages.

scimonster wrote:

If you want to make it so that people can't find the password by looking at the file source (say they get on your computer), so hash the input, and put the hash in the code instead of the password.

yea this is important..


SCRATCH'S PARTLY INSANE RESIDENT 
http://internetometer.com/imagesmall/31691.pnghttp://bluetetrarpg.x10.mx/usercard/?name=muppetds

Offline

 

#6 2013-01-22 10:47:55

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Password protected pages.

RedRocker227 wrote:

shouldn't

Code:

(!($enteredPass == $password))

be

Code:

($enteredPass!=$password)

that's what i always thought

Yep. I didn't notice that. Using != is shorter.

Offline

 

#7 2013-01-22 11:06:17

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Password protected pages.

You could do this in htaccess.

Offline

 

#8 2013-01-22 19:42:03

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Password protected pages.

scimonster wrote:

RedRocker227 wrote:

shouldn't

Code:

(!($enteredPass == $password))

be

Code:

($enteredPass!=$password)

that's what i always thought

Yep. I didn't notice that. Using != is shorter.

I didn't notice that either. It only took a few minutes to make.

scimonster wrote:

If you want to make it so that people can't find the password by looking at the file source (say they get on your computer), so hash the input, and put the hash in the code instead of the password.

I didn't really take much notice of that. You can still crack hashed passwords, but it is better than storing the password as plain text.

EDIT: I just realised that if someone has access to your computer, there is probably no point in hashing the password if someone can just open the file and see the contents of the file...

Last edited by nathanprocks (2013-01-22 19:47:17)


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#9 2013-01-22 20:03:03

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Password protected pages.

I think a better idea would be to save whether the user is authenticated in session data, so they only have to enter the password once.
That idea becomes even more useful when implementing something like this across an entire site (like Scratch 2.0).


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#10 2013-01-22 20:28:16

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Password protected pages.

jvvg wrote:

I think a better idea would be to save whether the user is authenticated in session data, so they only have to enter the password once.
That idea becomes even more useful when implementing something like this across an entire site (like Scratch 2.0).

Lol. I only made this because my friend wanted a personal page on his website... I guess it could be useful for some things. I already said "Feel free to change this any way you want!", so if you used this code yourself, maybe if your too lazy to write one yourself or something, you could modify it to do that.


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#11 2013-01-23 01:42:41

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: Password protected pages.

Cool script. Innovative use of the die() function, though I probably would have used if else logic to display content.  tongue


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#12 2013-01-23 01:59:31

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Password protected pages.

jji7skyline wrote:

Cool script. Innovative use of the die() function, though I probably would have used if else logic to display content.  tongue

Thanks!. Die() was the first thing that came into my head when I made this lol.


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

Board footer