【发布时间】:2021-10-11 12:11:18
【问题描述】:
所以,我试图创建一个帐户系统,我创建了一个有效的登录系统,但是当你输入错误的凭据时,我希望它在 ab 的值中显示“错误的用户名或密码”为空
标签,问题是我不知道如何访问
来自 app.js(node.js 项目)的标签
<div class="form">
<form class="login-form" action="/account" method="post">
<p id = "check"></p>
<h1 id = "login-text">Login</h1>
<label style="color:white;">Username:</label>
<input type="text" id = "username" placeholder="Enter Username" name="username" required>
<label style="color:white;">Password:</label>
<input type="password" id = "password" placeholder="Enter Password" name="password" required>
<button type="submit">Login</button>
<a href="register"><h5>register</h5></a>
</form>
</div>
</div>
app.post('/account', (req, res) => {
const username = req.body.username;
const password = req.body.password;
con.query("USE discbin")
con.query('SELECT * FROM accounts WHERE username = ?', [username], function (err, result, fields) {
if (err) throw err;
if (result.length > 0 && result[0].password === password) {
console.log(result[0].username + " logged in!")
res.render('account');
}
else {
console.log("a user tried to login using the username: " + username)
//set <p> to "wrong username or password"
}
});
});
【问题讨论】:
标签: javascript html node.js express ejs