Entrance Chat Gallery Guilds Search Everyone Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining the forum??
October 23, 2025 - @800.25 (what is this?)
Activity rating: Three Stars Posts & Arts: 36/1k.beats Unread Topics | Unread Replies | My Stuff | Random Topic | Recent Posts Start New Topic  Submit Art
News: :happy: Open the all windows! Your mind needs storms and air! :happy: Guild Events: There are no events!

+  MelonLand Forum
|-+  World Wild Web
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  safest way to have an admin page on my site?


« previous next »
Pages: [1] Print
Author Topic: safest way to have an admin page on my site?  (Read 290 times)
MediocreMetastasis
Sr. Member ⚓︎
****
View Profile WWWArt


Personal Text
⛺︎ My Room
Itch.io: My Games

Guild Memberships:
Artifacts:
Joined 2025!
« on: October 14, 2025 @702.67 »

I want an admin page on my site to do stuff like post,edit,and delete blogs.I currently have it setup where the page requires you to input a password and then you get admin permission throughout the site during the session

Code
    
$ADMIN_PASS = password_hash("Password123", PASSWORD_DEFAULT); // hashed
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $pass = $_POST['password'];

    if (password_verify($pass, $ADMIN_PASS)) {
        $_SESSION['is_admin'] = true;
        header("Location: home.php");
        exit;
    } else {
        $error = "Invalid password hacker.";
    }
    }

Is this a safe method or am I asking to be hacked?
Logged


Artifact Swap: Cheese StoneSideEyeDoggoDerp DoggoShocked DoggoSad DoggoHappy DoggoNeutral DoggoShocked SharaCool McgeeAgent JerrySunny the Puppy
Melooon
Hero Member ⚓︎
*****
View Profile WWWArt


So many stars!
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: melon
iMood: Melonking
Itch.io: My Games
RSS: RSS

Guild Memberships:
Artifacts:
coolest melon on the web!Emergency feel-good teaa silly heart 4 melon :)Hyperactive DonutGreat Posts PacmanThanks for being rad!
« Reply #1 on: October 14, 2025 @707.64 »

If your site is running over HTTPS then this is perfectly safe; its the same method that's used by most sites with passwords.

That said! You can improve this a little; instead of rehashing your password with the first line; just hash it once using some other script/online harsher then store the hashed version instead of the plain text version on your site (just make sure your verifier is using the same hash type that you saved).
That way even if by some sort of bug the source code leaks or is shown to a visitor they still cant get your password easily ^^

You can also improve the hash by looking into hash salts - those are basically extra bits of text that are included in the hashing algorithm so someone cant brute force unhash your hash using a huge library of pre-calculated hashes of common passwords ^^ (this is a very good idea for a public site like a forum with many passwords stored, but frankly for your case its not super important if you use a good password)
Logged


everything lost will be recovered, when you drift into the arms of the undiscovered

Artifact Swap: SapphireRising Star of the Web AwardMessage Buddy
MediocreMetastasis
Sr. Member ⚓︎
****
View Profile WWWArt


Personal Text
⛺︎ My Room
Itch.io: My Games

Guild Memberships:
Artifacts:
Joined 2025!
« Reply #2 on: October 15, 2025 @184.11 »

Cool. I'll make sure not to have my password in plaintext in my code. Thanks.
Logged


Artifact Swap: Cheese StoneSideEyeDoggoDerp DoggoShocked DoggoSad DoggoHappy DoggoNeutral DoggoShocked SharaCool McgeeAgent JerrySunny the Puppy
Dan Q
Jr. Member
**
View Profile WWW


I have no idea what I am doing
⛺︎ My Room
Itch.io: My Games
RSS: RSS

« Reply #3 on: October 15, 2025 @341.68 »

Seconding everything Melooon said, including "don't both with salting" - a salt only exists to make it harder to reverse-engineer a password if you've got the hashed version: so long as the (one) password on this site isn't one that you use anywhere else, that's probably not a concern for you anyway! (And by the time somebody's gotten onto your server to see the hash, you've got bigger problems than them being able to log in to your admin area!)

Just don't forget to check for $_SESSION['is_admin'] on every single page that needs it. I see lots of people do things like make a login page (which checks a password and sets a session), then create a page that handles creating posts (which checks the session and then does things), and then create a page that handles deleting posts (which just deletes things without checking that the $_SESSION['is_admin'] is set and... uh-oh, that's a problem!).

Don't forget to add a logout link that goes to a page that unsets the session variable and then redirects back home, or whatever! You never know when you're going to need a logout link!

And finally - and for a small personal site you definitely don't need to think about this rightaway - down the line, consider the possibility of cross-site request forgery attacks. E.g. if you have a page that (a) checks you're logged in as an admin and then (b) deletes a post... is it possible for an attacker to put a malicious link in an email or on their own website that, (if you're logged-in when you're tricked into clicking it) goes to that page, resulting in a post deletion? The risk is infinitesimally small for a small personal site unless you've made a lot of enemies!

Love the direction you're going in, anyway. PHP empowers the world of the "mildly dynamic website", a particularly magical and special category that's close to my heart.
Logged


Artifact Swap: I met Dan Q on Melonland!PolyamoryJoined 2025!
Rubbereon
Casual Poster ⚓︎
*
View Profile


⛺︎ My Room

Artifacts:
Joined 2025!
« Reply #4 on: October 17, 2025 @642.79 »

I only have a static website, but have been interested in starting a forum myself and my expert's opinion is that adminstration is usually done through something like phpmyadmin or directly through the server if you have a physical access to it.

Some forum softwares like xenforo let you make an admin account that can do those things, but if somebody comes in and try to do a dictionary attack it leaves your forum open to get raided.

At least with phpmyadmin they'd need a direct link to the panel, and you can install it anywhere you want (lets' say mywebsite.com/foo/bar/phpmyadmin.php) and so only you will know where to go to administrate your website.
« Last Edit: October 17, 2025 @644.36 by Rubbereon » Logged

Fuzzy fwiend
Linux user
You can also find me on Comfybox.
Melooon
Hero Member ⚓︎
*****
View Profile WWWArt


So many stars!
⛺︎ My Room
SpaceHey: Friend Me!
StatusCafe: melon
iMood: Melonking
Itch.io: My Games
RSS: RSS

Guild Memberships:
Artifacts:
coolest melon on the web!Emergency feel-good teaa silly heart 4 melon :)Hyperactive DonutGreat Posts PacmanThanks for being rad!
« Reply #5 on: October 17, 2025 @651.39 »

phpmyadmin
phpmyadmin is not a website admin interface :smile: Its a frontend for editing MySQL databases that is made in PHP. MySQL databases are a particular technology that can be used alongside PHP and other programing languages to store and manage large amounts of data; they are definitely very useful to know about, but generally you don't manage a website by editing SQL data directly. An admin interface is usually a nice UI that will have scripts that safely edit the SQL database for you. Most people use phpmyadmin (or other SQL frontends) only when they are setting up databases or bug fixing issues :wizard: Though I agree its a slightly confusing name!

(I also don't actually approve of using phpmyadmin since you should never have SQL access exposed on the web, but I do understand why people use it since its more complex to setup more secure systems!)
Logged


everything lost will be recovered, when you drift into the arms of the undiscovered

Artifact Swap: SapphireRising Star of the Web AwardMessage Buddy
Pages: [1] Print 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | ~ Send Feedback ~ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi