database - Password protect a page without db access with php -
Is it possible to password protect a page without access to DB? I only have some pages but I should be able to change passwords and save session etc. And I want a safe way because it is for the production site!
How to submit it to MD5 after config.php:
If this is a good idea, is it a way to restrict access to this php from a single script, which is called check.php or something else?
Sure, why not? You can use flat files in the inaccessible directory (protected by .htaccess or secured with www root) and can be used as a database.
Here is a simple entry class that I have killed:
class simple login {personal $ user; Private $ db = './pass.txt'; Function __ construct () {$ data = file_get_contents ($ this-> db); If (! $ Data) {dead ("DB can not be open"); } And {$ this- & gt; User = unassigned ($ data); }} Save the function () (if (file_put_contents ($ this- & gt; db, serialize ($ - user)) === false) ('Could not save data');} Authenticate function ($ User, $ password) {return $ this- & gt; user [$ user] == $ this- & gt; hash ($ password);} addUser function ($ user, $ password) {$ this-> users [$ User] = $ this- & gt; hash ($ password); $ this-> save ();} delete function user ($ user) {unset ($ this-> users [$ user]) ; $ This-> save ();} function userExists ($ user) {return array_key_exists ($ user, $ this-> users);} function userList () {return array_keys ($ this-> users) ;} // You can change the hash function and salt here function hash ($ password) {$ salt = 'jafo2ijr02jfsau02!} U (JF'; return sha1 ($ password. $ Salt.)}}}
< / Pre>Note : If you are going to use it in the actual server, then you should actually turn off error reporting by calling it or
Example of use : and
file_put_contents
(ie: therefore It changes to@file_get_contents
) P>
Comments
Post a Comment