Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 不通过url节点传递值_Html_Node.js_Express_Authentication_Ejs - Fatal编程技术网

Html 不通过url节点传递值

Html 不通过url节点传递值,html,node.js,express,authentication,ejs,Html,Node.js,Express,Authentication,Ejs,我已经创建了一个登录系统,正在尝试散列密码,或者不通过url发送密码。我在前端有一个表单,它基本上接收用户输入,将其与数据库中存储的密码进行比较,如果相同,则只允许他们进入站点,如果不相同,则不允许。但是,它很容易通过url访问。如果密码正确,您可以在url中看到它。我想知道是否有办法避免这种情况发生?不知道是否有。提前谢谢 代码如下: 该网站尚未托管,因此无法共享,但以下是代码 前端: <form method="GET" action="/login&q

我已经创建了一个登录系统,正在尝试散列密码,或者不通过url发送密码。我在前端有一个表单,它基本上接收用户输入,将其与数据库中存储的密码进行比较,如果相同,则只允许他们进入站点,如果不相同,则不允许。但是,它很容易通过url访问。如果密码正确,您可以在url中看到它。我想知道是否有办法避免这种情况发生?不知道是否有。提前谢谢

代码如下:

该网站尚未托管,因此无法共享,但以下是代码

前端:

 <form method="GET" action="/login">
                <div class="form-group">
                  <input type="text" class="form-control form-control-user" id="inputUsername" name="inputUsername" aria-describedby="emailHelp" placeholder="Enter Email Address...">
                </div>
                <div class="form-group">
                  <input type="password" class="form-control form-control-user" id="exampleInputPassword" name="inputPassword" placeholder="Password">
                </div>
                <div class="form-group">
                  <div class="custom-control custom-checkbox small">
                    <input type="checkbox" class="custom-control-input" id="customCheck">
                    <label class="custom-control-label" for="customCheck">Remember Me</label>
                  </div>
                </div>
                <button class="button" type="submit">SUBMIT</button>
                <hr>
                <a href="index.html" class="btn btn-google btn-user btn-block">
                  <i class="fab fa-google fa-fw"></i> Login with Google
                </a>
                <a href="index.html" class="btn btn-facebook btn-user btn-block">
                  <i class="fab fa-facebook-f fa-fw"></i> Login with Facebook
                </a>
              </form>

记得我吗
提交

后端:

app.get('/login', (req, res) => {

//declaring variables
const inputUsername = req.query.inputUsername;
const inputPassword = req.query.inputPassword;





var userLogin = "select * from login where USERNAME = '" + inputUsername + "' AND PASSWORD = '" + inputPassword + "'";
ibmdb.open(dbString, function (err, conn) {
    if (err) return console.log(err);
    conn.query(userLogin, function (err, rows) {
        if (err) {
            console.log(err)
            }
            if (rows.length > 0) {
                console.log('trying to render index')
                //userAuth = "true";
                userName = inputUsername;

                for (var i = 0; i < rows.length; i++) {
                    firstName = rows[i]['FN']
                    lastName = rows[i]['LN']
                    company = rows[i]['COMPANY']
                    
                }
                res.redirect('/index')
            } else {
               // userAuth = "false";
                res.render('login.ejs')   
                alert('Incorrect username or password. Please try again')
            }

           
        })
    })
})
app.get('/login',(req,res)=>{
//声明变量
const inputUsername=req.query.inputUsername;
const inputPassword=req.query.inputPassword;
var userLogin=“从用户名='”+inputUsername+“'和密码='“+inputPassword+””的登录名中选择*;
open(dbString,function(err,conn){
if(err)返回console.log(err);
conn.query(userLogin,函数(err,行){
如果(错误){
console.log(错误)
}
如果(rows.length>0){
console.log('尝试呈现索引')
//userAuth=“true”;
用户名=输入用户名;
对于(变量i=0;i

信息通过如下url传递:localhost:9999/login?inputUsername=testUser1&inputPassword=testPass1更改为POST请求

只需将
method=“GET”
更改为
method=“POST”
,然后在后端将
app.GET('/login',
更改为
app.POST('/login',
req.query.inputUsername
更改为
req.body.inputUsername
(包括另一个)



您还应该使用准备好的查询,就像您的脚本对sql注入开放一样。因此,将
where USERNAME='“+inputUsername+”
更改为
where USERNAME=?
(包括另一个)并传递参数,如
conn.query(userLogin,[inputUsername,inputPassword],函数

np,有相当一部分需要调整;p需要注意的是,如果您打算使用SSO(使用Google/Facebook登录)您将需要以不同的方式实现登录,很可能会删除大部分当前代码。按照您所做的,它工作得很好。但是,当我进入第二部分时,它似乎失败了。这可能是由于格式不正确。我有这样的代码。var userLogin=“从用户名=?和密码=?”的登录名中选择*会给我一个错误,“cb&&cb(err,db);^TypeError:cb不是一个函数“回复最近的评论。我不打算使用fb或google登录。我使用的是创建一个只允许特定预定义用户登录的应用程序。感谢您提到这个想法:)是的,我提到它是因为HTML代码说使用..登录,您使用的数据库库是什么,不确定会导致
“cb&&cb(err,db);^TypeError:cb
肯定是的。你能告诉我找到lib的方向吗?对不起,我不知道在哪里能找到它