Skip to content

A minimal PHP script to easily create password protected areas on a server without the need for a database.

License

Notifications You must be signed in to change notification settings

DieTapete/restricted-area

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

restrictedArea

A minimal PHP script to easily create password protected areas on a server without the need for a database. The script ships with a download area that lists the files of a specific folder but you can easily adapt it for anything you like.

Warning: I am not a professional PHP programmer and there are probably still a lot of security flaws in this code. The script should not be used in it's current state. Contributions are very welcome.

Usage

  • Open config.php and remove the line define('DEBUG', TRUE);. Also edit the other variables like TITLE as needed.
  • Upload all the files to a directory on your server. Hint: It's not recommended to upload create_hash.php though. Use it in a local environment instead.
  • Run create_hash.php in a web browser to generate a hash for a password.
  • Open config.php and paste the generated hash into the LOGINS array. Remove the entry for user1.
  • For each user create a folder in the download directory that you defined in config.php. For security reasons it is strongly recommended to use a folder in the non public area of the server (document root). If that is not possible just keep the default files directory or copy the .htaccess file from it to your alternative download folder.

Info

The script comes with an example user named user1 and the password password. There is also an example file in the folder files/user1 for the user to download.

How does it work?

Basically you generate a hash (create_hash.php) for each user and save them in an associative array with the user names as keys. When a user logs in the script iterates through the array and the password is being validated. On validation two session variables are being set containing the username and the hash combined with the user agent string. These variables are used to check if the user is authorized (see authorized function in functions.php). The hashing algorithm is implemented in includes/pw.php and uses PBKDF2 (hash_pbkdf2 is used only if it exists) and SHA256 with 30000 iterations.

When logged in the user is able to see the files of a folder named after the user within the specified download directory. By default the download directory is the folder files, which is protected by a Deny from all rule in the .htaccess file. It is recommended to use a non public folder instead since the access rule can be circumvented.

The download script download.php first checks if the user is authorized. Then the received GET variable file is urldecoded and checked if it contains the string '../' to prevent accessing files from a parent folder. The file variable is concatenated with the download directory and the username and served to the user via readfile if it exists.

Third Party Usage

ToDo

Release History

  • 0.2.0 Added modules system
  • 0.1.0 Initial release

About

A minimal PHP script to easily create password protected areas on a server without the need for a database.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published