我确定需要做一些工作才能确定它可以实现。我很高兴听到有关以下情况的意见和建议:
我需要一个用户登录的网络软件。所有用户都有一个用户帐户,并且可以拥有0-3个辅助用户帐户,他们可以在验证时通过主网站使用。辅助用户帐户由第三方JavaScript库控制,但我可以控制存储在数据库中的用户名和密码。
目标是让用户不必多次进行身份验证,只需使用一个用户帐户,而且这些用户帐户应该通过脚本自动运行。
那么,是否有可行,安全和正确的方法来实现这一目标?我知道在脚本中使用用户名和密码本身就是一个安全问题,但希望如果不能正确完成,我可以找到下一个最好的东西。我将使用Asp.Net MVC作为平台,使用ajax进行所有调用,因此该软件看起来和感觉就像一个单页应用程序。然而,底层技术无关紧要,可以在这里使用任何服务器端技术。
有一些选项可供选择:
在这里,有人认为我一直在玩弄:
首先显示登录页面。身份验证通过ajax完成,凭据保存在登录表单上,当用户登录时隐藏。在登录调用的成功回调事件中,我们可以显示ajax调用可以返回的主要内容(这可能类似于经过身份验证的用户的主页。由于原始凭据字段仍在页面上,因此可以通过脚本访问这些字段并用于辅助系统凭据。
但是,我并不相信这是一种处理辅助系统登录的安全方法,即使我可以在整个网站上安装https。我只是不知道这里的实际安全问题是什么。评论,专家?更好的方法来实现同样的目标?
登录页面和主要结构可能如下所示(一个非常简单的例子):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="/Scripts/jquery-2.1.0.min.js"></script>
<script type="text/javascript">
function VerifyUser(name, pass, remember, container) {
$.ajax({
type: 'POST',
contentType: 'application/json; charset=UTF-8',
url: 'Account/VerifyUser',
data: JSON.stringify({ "userid": name, "password": pass }),
processData: false,
success: function (response) {
if (response.Success) {
// Here I could stash the password somewhere if needed.
// It's not visible in the source code but it is accessible via jquery
$('#secondarypass').val(pass);
// Here I can show the html data that the ajax call could return, or
// send out another ajax call to retrieve the actual content separately.
//Show here data that was returned by ajax call in response object. This could be a main page etc
$("#maincontainer").show();
$("#maincontainer").html(response.Message);
$("#logincontainer").hide();
}
},
error: function (a, b, c) {
$("#maincontainer").show();
$("#maincontainer").html(a.responseText);
}
});
return false;
}
</script>
</head>
<body>
<div class="page">
<input id="secondarypass" type="password" />
<div id="logincontainer">
<input id="UserName" name="UserName" type="text" value="" />
<input id="Password" name="Password" type="password" />
<button onclick="javascript:VerifyUser($('#UserName').val(), $('#Password').val());">Log In</button>
</div>
<div id="message"></div>
<div id="maincontainer">
<!-- this is where the main content of the software would be -->
</div>
</div>
</body>
</html>
ajax调用可以返回类似这样的内容
<script type="text/javascript" src="/Scripts/secondarysystem.js"></script>
<script type="text/javascript">
function SecondaryLogin() {
var data = {
'username': 'mysecondaryusername',
'pass': $("#secondarypass").val() //NOTE here I could access the password-stash I set up earlier
};
var system = new SecondarySystem(); //This could be an object from the secondarysystem.js library
system.LogIn(data);
// this could have a onsuccessfullogin callback event, where we could populate some secondary system specific data to the div below
}
</script>
<div id="secondarycontainer">
</div>
在此设置中,页面刷新会导致问题,但我可以禁用f5(或通过重新加载正确的内容替换它)并至少添加一个对话框,说明&#34;刷新将强制您重新登录,确保离开这个页面?&#34;等
答案 0 :(得分:2)
你一直在玩的想法,听起来不错,而且我们很多人都在练习。你提到的很少有你不想面对的问题,如果你真的要把它作为单页应用程序,你可以记住这些问题。
1.Refresh F5
如果刷新是您的问题,您可以使用localstorage,这样在页面刷新时您的用户名和密码不会丢失。
- 安全吗?
醇>
我认为您可以存储加密的密码变量,这样您只需在对用户进行身份验证时对其进行解密。对于加密,您可以参考https://sourceforge.net/projects/pidcrypt/(URL更新)。