gpt4 book ai didi

javascript - 前端还是后端匹配密码?

转载 作者:数据小太阳 更新时间:2023-10-29 05:43:59 25 4
gpt4 key购买 nike

是否有人知道有关检查匹配密码的行业标准或最佳实践的信息(例如 Gmail 的“密码不匹配”反馈)?它是后端、前端还是客户端流程?或者是否完全基于其他因素?

这是我使用的代码示例(带有 Bottle 的 Python)来注册用户。代码有效,但我不确定是否应该提供 flash message从后端(返回“密码不匹配”)还是使用 JS 之类的东西更好?我知道有脚本可以验证这一点,但它们都是 JS。我的问题不是如何使用 JS 来实现,而是首选方法。

@route('/suser', method='POST')
def sign_suser():
cemail = request.forms.get('semail')
cpassword1 = request.forms.get('spass1')
cpassword2 = request.forms.get('spass2')
ctype = request.forms.get('stype')
if cpassword1 != cpassword2:
return "<p>Passwords do not match</p>"
else:
pwhash = crypt(cpassword1)
connection = sqlite3.connect("whatever.db")
cursor_v = connection.cursor()
cursor_v.execute("insert into users (cemail, cpassword, atype) values (?,?,?)", (cemail,pwhash,ctype))
connection.commit()
cursor_v.close()
info = {'status': 'User Added',
'type': 'success'}
return template('whatever',info)

最佳答案

在注册期间检查两个密码字段是否匹配应该完全由客户端逻辑完成。提供它是为了防止用户错误地将拼写错误插入他们的密码。服务器端检查毫无意义,因为您的客户会阻止它,如果您的用户是精通技术的人,他会使用 curl 做所有事情,那么如果他们搞砸了,责任在他们身上。

此外,我将详细说明您关于最佳实践的问题。你不应该立即将用户保存在你的数据库中,除非他们首先通过链接(通常发送到他们的电子邮件)验证它是有效的。请记住:永远不要相信用户提供的任何东西。

关于javascript - 前端还是后端匹配密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42190530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com