0

Just started learning JavaScript can someone please tell me what is wrong with this code

<!DOCTYPE html>
<html>
<body>

<h1>Password Requirement</h1>

<p id="demo">Please enter your password</p>
<input id="myInput" type="text" >

<script>
function myFunction()
var a=document.getElementById("demo")
var b=document.getElementById("myInput").value
var c=document.getElementById("myBtn")

if (b=="26a8f9e"(b))
       {
       alert("Correct")
       }
else
       {
       alert("Incorrect")
       }

</script>


<button type="button" id="myBtn" onclick="myFunction()">Submit</button>

</body>
</html>
4
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by amrita111
0

b=="26a8f9e"(b) whould be b === '26a8f9e'

With that said, this does not provide any security whatsoever since anyone can just view source and get the password.

0

Use server-side processing to deal with passwords. If you don't want a page refresh on form submit, you can use Ajax. js can help with validation only to notify users that they've typed illegal characters if the only ones allowed are a-Z0-9 for example. As mentioned, anything in your js files or js scripts within html pages can be read - even if you use an obfustator. It is not secure.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.