gpt4 book ai didi

java - 密码验证

转载 作者:行者123 更新时间:2023-12-02 06:36:32 25 4
gpt4 key购买 nike

我需要我的代码来检查密码,并且密码中的字母之一应为大写。当用户进入时。请协助。

        int digcheck=0,charcheck=0,symbcheck=0;
for (int i = 0; i < passwordraw.length(); i++) {
if (Character.isDigit(passwordraw.charAt(i)))
{
digcheck++;
}
else if(Character.isLetter(passwordraw.charAt(i)))
{
charcheck++;
}
else
{
symbcheck++;
}
}
if(digcheck<3)
{
digcheck=0;
throw new OBSSecurityException("INVALID PASSWORD! Must have atleast three(3) digits.");
}else if(charcheck<5)
{
charcheck=0;
throw new OBSSecurityException("INVALID PASSWORD! Must have atleast five(5) alpha.");
}
else if(symbcheck<1)
{
symbcheck=0;
throw new OBSSecurityException("INVALID PASSWORD! Must have atleast one(1) symbol.");
}

最佳答案

使用正则表达式。

使密码与.*[A-Z]+.*匹配这将使您的密码至少包含一个大写字符

[编辑]您还可以使用正则表达式来查找其他限制。

要拥有至少 3 位数字,您可以使用此正则表达式

.*[0-9]{1}.*[0-9]{1}.*[0-9]{1}.*

这将匹配任何内容加 1 位数字、更多任何内容、至少一位数字等等。您可以使用与其他验证类似的正则表达式,如果您需要帮助,请告诉我们

关于java - 密码验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19584915/

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