ここでは簡単にするためにエクスプレスフレームワークを使用しました。
HTMLフォーム "のindex.html"
<html>
<head><title>Login</title></head>
<body>
<form action="myaction">
<input type="text" name="mytext"/>
<input type="password" name="mypass"/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
と上のサーバー側の
は、[この質問](HTTPの
var express = require('express');
var fs = require('fs')
var app = express.createServer();
app.get("/", function(req, res) {
fs.readFile("index.html", function (err, data) {
if (err) {
res.contentType("html");
res.send("File not found");
}
else{
res.contentType("html");
res.send(data);
}
});
});
app.get("/myaction", function(req, res) {
if(req.param("mytext") === "admin" && req.param("mypass") === "admin"){
res.contentType("html");
res.send("You are authenticated");
}
else{
res.contentType("html");
res.send("Invalid Username or password");
}
});
app.listen(8000);
console.log("Server running on localhost:8000");
が重複する可能性を "app.js":// stackoverflowの。 com/questions/3498005/user-authentication-libraries-for-node-js)を参照してください。 – Twisol
真の複製、単にexppress + passport/everyauthを使用すると、すべてがそれらによって注意を払われます。 –