簡體   English   中英

不通過 url nodejs 傳遞值

[英]Not passing values through url nodejs

我創建了一個登錄系統,並試圖對密碼進行哈希處理,或者不通過 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')
            }

           
        })
    })
})

並且信息通過這樣的網址傳遞: localhost:9999/login?inputUsername=testUser1&inputPassword=testPass1

更改為 POST 請求

只需將method="GET"更改為method="POST" ,然后在后端將app.get('/login',更改為app.post('/login',並將req.query.inputUsernamereq.body.inputUsername (包括另一個)。


您還應該使用准備好的查詢,因為您的腳本對 sql 注入開放。 因此,將where USERNAME = '" + inputUsername + "'更改為where USERNAME = ? (包括另一個)並傳遞像conn.query(userLogin, [inputUsername, inputPassword], function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM