HTML and Javascript are interpreted on the client side. For login purposes, this is server-side code that is usually used to verify credentials — simply because the fact that you already know about — with a simple client-side implementation, you can see the credentials in the server-side source code the side is also easier to work, as soon as you understand it, it is more flexible for further development, it is safer and really used everywhere for this task.
It is a good idea to use PHP, ASP, Ruby (or any other server language ) for this. If you do not want this, you need to make it so that the user can read the credentials from the source code.
For this, you can use various methods, such as cryptography or obfuscation . Cryptography is highly recommended for obfuscation, as this proves the added security of your application. Obfuscation basically means that you change the source code in such a way that it is difficult to read - you add functions that encode strings, so that your “password” cannot be seen at a glance. However, obfuscation can always be bypassed, and usually pretty easy with good debugging tools.
So let go of cryptography. Here you are looking for one-way hash functions . You have a choice - MD5, SHA1, SHA256, ... each provides a different level of security. The implementation of SHA256 in Javascript is an example that you can use. There are many other libraries and examples for this, so just use Google and find the one you like.
Now what to do about it? Say you have a sha256 () function that takes a string and returns a hash as a string. For each user and your password, you set the SHA256 hash of the string "user + password".
Say you want your username to be “Pedro” and the password for this account is “MyPassword”.
You set the hash "PedroMyPassword" - for example, with online hashing . You can see that its SHA256 hash
40be6e939eedf018b2b846e027067dcb006585a2155ce324f1f2a6a71d418b21
This hash is what you injected into your Javascript code.
When the user enters his username and password, you call the sha256 function on "username + password" and you compare it with a predefined hash.
Please note that you need to choose a really strong password, otherwise some attacks (like a dictionary attack) will be easy to use to break the hash.
The problem is that you did not indicate what you want to do next. For example, you can redirect authenticated users to the next page, but here you have the same problem again - if you redirect in Javascript to "secondpage.html" in your code, someone can simply skip authentication and go to this second page.
What you can do in this case is that you name the second page as
40be6e939eedf018b2b846e027067dcb006585a2155ce324f1f2a6a71d418b21.html
i.e. your user's hash + skip line. In this option, you do not put the hash in the code at all. The web server will simply return a 404 error for all users who are not authenticated. For example, if someone tries to use “Pedro” with “123456” as a password, SHA256 will
3bac31720fdd4619ebe2e8865ccc0dc87eb744f3f05f08c628bb9217a77e4517
and if you redirect them to
3bac31720fdd4619ebe2e8865ccc0dc87eb744f3f05f08c628bb9217a77e4517.html
it will not exist because your second page file is called
40be6e939eedf018b2b846e027067dcb006585a2155ce324f1f2a6a71d418b21.html
You will need to create these two pages for each user / pass combination. Then you could put a simple redirect code on the real second page.
But make sure you use the HTTPS protocol, otherwise the pages will go through an unencrypted wire ...
All this will work, but nonetheless, I highly recommend that you consider the server path.