This html code below is suppose to execute and launch an alert asking for a username and if you get the username correct than it will ask for a password but nothing happens if i open this page in a browser. Why this doing this? What am I missing? Please don't tell me this is a unsecure way to do this I already know I'm just improvising until I implant a better way.
<html>
<head>
<script language="JavaScript">
var username;
var user1="grant"
username=prompt('Please Log in. Username:',' ');
if (username=user1);
var pass1="password";
password=prompt('If you are suppose to be here you have a password. Please type it now:',' ');
if (password==pass1);
else {
window.location="wrongpassword.html";
}
else {
window.location="wrongpassword.html";
}
</script>
<body>
</body>
<html>
This html code below is suppose to execute and launch an alert asking for a username and if you get the username correct than it will ask for a password but nothing happens if i open this page in a browser. Why this doing this? What am I missing? Please don't tell me this is a unsecure way to do this I already know I'm just improvising until I implant a better way.
<html>
<head>
<script language="JavaScript">
var username;
var user1="grant"
username=prompt('Please Log in. Username:',' ');
if (username=user1);
var pass1="password";
password=prompt('If you are suppose to be here you have a password. Please type it now:',' ');
if (password==pass1);
else {
window.location="wrongpassword.html";
}
else {
window.location="wrongpassword.html";
}
</script>
<body>
</body>
<html>
Share
Improve this question
asked Nov 2, 2013 at 16:04
applesapples
1472 gold badges6 silver badges16 bronze badges
3
-
if (username=user1);
Really? ... single=
,;
after if expression, and no curly braces? – XCS Commented Nov 2, 2013 at 16:07 -
Also the
language
attribute on thescript
tag is deprecated. Usetype="text/javascript"
. – Ingo Bürk Commented Nov 2, 2013 at 16:11 - Please clarify who you are referring to. – Ingo Bürk Commented Nov 2, 2013 at 16:16
2 Answers
Reset to default 2You are missing some braces. Corrected code (fiddle: http://jsfiddle/RyjhP/1/):
var user1="grant";
var username=prompt('Please Log in. Username:',' ');
if (username==user1){
var pass1="password";
password=prompt('If you are suppose to be here you have a password. Please type it now:',' ');
if (password==pass1){
alert("correct!")
}
else {
window.location="wrongpassword.html";
}
}
else {
window.location="wrongpassword.html";
}
short way to do that.
js
window.onload=function(){
window.location=prompt('Enter Pass')!='password'?'wrong.html':'ok.html'
}
example
http://jsfiddle/6KzDJ/
but this is a very bad thing.
you should check the password from a secure location with ajax.