r/learnjavascript • • 14d ago

Simple Password input field

Hi all, I've been learning webcoding recently and Ive been wanting to make a website to use as a prop in my tabletop games.

My biggest desire right now is to do a password input where submitting an incorrect input displays an error message, while the correct input provides a redirect to a new page.

Since this will only be for my friends and wont host any private data, I'm not too concerned for heavy security, but most resources online are for actual websites and online security. Whats the best way for me to implement something like this?

6 Upvotes

12 comments sorted by

View all comments

1

u/Fluffy-Salary-6998 13d ago

If you do not want the password in the source at all, use it as the page name. Name the secret page `dragon.html` and do `fetch(pw + '.html', {method: 'HEAD'})`, if response is ok then `location.href = pw + '.html'`, if not show the error. Now there is nothing to find in devtools, not the password and not the url, wrong guess is just a 404. Works on static hosting, but not when you open the file from disk, fetch needs http. Hashing hides the password but the vault url still sits in the code.