[英]Looping a login prompt in node.js?
I wasn't quite sure how to title this question, open to edits. 我不太确定如何为这个问题加上标题,以便进行编辑。
This is what I am currently using for the login system. 这是我当前用于登录系统的内容。
if (accountq === "Add", " Add", " Add "){
var usrin = prompt("Username: ")
}
if (usrin === usrname){
var passin = prompt("Ah, hello. Password?: ")
}
do {
if (passin !== pswdb){
var passin = prompt("Sorry, that pass does not match.")
}
}
while(passin === pswdb){
console.log("Username and password have been authenticated")
var addname = prompt("Name: ")
console.log(
"Okay, noted that. Please give us the direct download link"
)
var directlink = prompt("Direct Link: ")
console.log("Thank you! Will add that.")
}
while(passin !== pswdb){
wrongpass()
} //this was my attempt to trigger the prompt again, but it failed.
I am trying to prompt for a password until a correct password is entered, and then go on to the rest of the code, I've tried while, but with no luck, can someone point me in the correct direction. 我试图提示输入密码,直到输入正确的密码为止,然后继续进行其余的代码。我试了一段时间,但没有运气,有人可以向我指出正确的方向。
How about this? 这个怎么样? It's simple, small, and seems similar to your attempted solution: 它简单,小巧,看起来与您尝试的解决方案类似:
var prompt = require('prompt-sync')()
var expectedPass = 'myPassword'
while (true) {
var username = prompt('Username:')
var password = prompt('Password:')
if (password == expectedPass) break
else console.log('Sorry, that pass does not match.')
}
console.log('Match!')
/* ... rest of code ... */
Please note the following security and performance bits: 请注意以下安全性和性能位:
prompt-sync
is a blocking prompt, which means any other asyncronous activities will be blocked until the user responds. prompt-sync
是一个阻止提示,这意味着任何其他异步活动都将被阻止,直到用户做出响应为止。 This won't be a prompt unless you're doing other things in this process. 除非您在此过程中执行其他操作,否则不会提示您。
Security-wise, a user could simply open the file and read the password to get around this security prompt. 在安全方面,用户只需打开文件并阅读密码即可解决此安全提示。
If either of these are problems, then you may be looking for a different solution. 如果这两个都是问题,那么您可能正在寻找其他解决方案。 Let me know if that's the case! 让我知道是否是这样!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.