我在公共文件夹中使用静态页面loginform.html,并以此形式在用户按提交时将用户名和密码发送到服务器路由/登录,并在此路由中进行身份验证。
在服务器端:
var express = require('express');
var app = express();
app.use(express.compress());
app.use(express.static(__dirname + '/public'));
var a = ['/'];
app.get('/', function(req, res) {
console.log('First page called');
res.redirect('loginform.html');
res.end();
});
app.post('/login', function(req, res) {
console.log('login called');
//authentication Check//
res.end();
});
app.listen(process.env.PORT || 3000);
在CLient方面:
<html>
<style media="screen" type="text/css">
@import url("css/loginform_styles.css");
</style>
<head>
<title>
Welcome to Label
</title>
<script type="text/javascript" src="annotationTools/js/md5.js" ></script>
<script>
function validateForm()
{
var usrnamefield=document.forms["loginform"]["usrfield"].value;
var passwrdfield=document.forms["loginform"]["passfield"].value;
if ((usrnamefield==null || usrnamefield=="")||(passwrdfield==null || passwrdfield==""))
{
document.getElementById('valueerrorlayer').innerHTML ='Username or password field is empty';
//document.forms["loginform"]["errorshow"].innerHtml = 'username or password empty';
return false;
}
else return true;
}
</script>
</head>
<body>
<div id = "imge_disp">
<img src="images/logo.jpg"/>
</div>
<form name="loginform" id="loginform" action="login" method="post" onsubmit="return validateForm()">
<div id = "content" align = "center">
<p align="center"><font size="7">LabelDev</font></p>
<br />
<br />
<label> Please Enter the <b><i>Username</i></b></label>
<br />
<br />
<input type="text" name = "usrfield" id = "usrfield" onkeydown="if (event.keyCode == 13) document.getElementById('btnSearch').click()"/>
<br />
<br />
<br />
<label> Please Enter the <b><i>Password</i></b></label>
<br />
<br />
<input type="password" name = "passfield" id = "passfield" onkeydown="if (event.keyCode == 13) document.getElementById('btnSearch').click()"/>
<br />
<br />
<br />
<i><p id='valueerrorlayer' style="color:red;"> </p></i>
<input type="submit" value="Submit"/>
</div>
</form>
</body>
</html>
问题:我希望用户名和密码在帖子上发送,以便中间人无法读取它们(散列或加密) 问题1:对于使用enctype =“application / x-www-form-urlencoded”的解决方案是否足够? 问题2:最好是保留在http中并进行身份验证。如果是,你可以指导我吗? 问题3:或转到https,然后如何创建ssl证书。
答案 0 :(得分:0)
经过研究,我使用HTTPS
证书和密钥来保护流量。