【发布时间】:2019-04-19 08:09:06
【问题描述】:
我在下面给出的html中有一个html登录页面
<html>
<head>
<title>Login Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form id="myform" action="API.html" method="get">
Username : <input type="text" name="username" required><br /><br />
Password : <input type="text" name="password" required><br /><br />
<input type="submit" id="sub" name="submit">
</form>
</body>
</html>
我还有另一个html页面,它是前一页的动作页面
<!DOCTYPE html>
<title>API INTEGRATION</title>
<link rel="shortcut icon" href="">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script>
<body>
<script>
var username = "........";
var password = "........";
if ($.get("username") == username && $.get("password") == password) {
var settings = {
"async": false,
"crossDomain": true,
"url": "https://........../test2/api/v1/sdk_initialize",
"method": "GET",
"headers": {
"Content-Type": "application/json",
"cache-control": "no-cache",
"Authorization": "Basic " + btoa(username + ":" + password),
}
}
var result = $.ajax(settings).done(function(response) {
});
var token = result.responseJSON;
var settings = {
"async": false,
"crossDomain": true,
"url": "https://........./test2/api/v1/Events/10?search=All ",
"method": "GET",
"headers": {
"Content-Type": "application/json",
"cache-control": "no-cache",
"Token": token,
}
}
$.ajax(settings).done(function(response) {
console.log(response);
});
} else {
alert("incorrect Login Details");
}
</script>
</body>
</html>
我正在尝试从登录页面获取用户名和密码,然后想将其与我设置的用户名和密码进行比较,如果正确,则执行某些任务,否则会提供不正确的登录详细信息的输出。
但即使我使用相同的登录凭据,我总是得到一个输出为“不正确的登录详细信息”而不是 json 对象?
我也想知道($.get("username")==username && $.get("password")==password)这个代码对不对?
【问题讨论】:
-
来自here,我不认为这是你使用
$.get()的方式 -
您应该验证这些服务器端。任何检查您的 js 代码的人都可以看到用户名和密码。
-
正确的密码处理包括:1)
<input type="password">2) 服务器端验证 3) 为密码设计的单向哈希(BCRYPT、Argon2i...)。这样做意味着与您尝试构建的开发工作量相同。
标签: javascript jquery html node.js