+ 1
Password Validator
Can someone help me with this password validation code. It must contain at least 2 uppercase, 3 lowercase & 1 digit........ https://code.sololearn.com/cefU63K5cxFJ/?ref=app
5 Antworten
+ 3
import java.util.Scanner;
public class password {
public static void main(String[] args) {
String pssWrd;
char ch;
int upprLtr =0;
int lwrLtr=0;
int numBr=0;
int specChr=0;
Scanner input = new Scanner(System.in);
System.out.println("Enter New Password: ");
System.out.println("Must Contain 2 Uppercase, 3 Lowercase, & 1 Digit: ");
pssWrd = input.nextLine();
for(int i = 0; i < pssWrd.length(); i++)
{
ch = pssWrd.charAt(i);
if(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||ch=='6'||ch=='7'||ch=='8'||ch=='9')
{
numBr = numBr+1;
}
if(Character.isUpperCase(ch))
{
upprLtr++;
}
if(Character.isLowerCase(ch))
{
lwrLtr++;
}
if(ch == '!' || ch== '@' || ch=='#' || ch=='#x27; || ch=='%'||ch=='^' || ch=='&'||ch=='*'||ch=='_' || ch=='-' )
{
specChr++;
}
}
if(numBr<1){
System.out.println("Invalid amount of numbers");
}
else if(upprLtr <2){
System.out.println("Invalid amount of Uppercase Characters");
}
else if(lwrLtr<3){
System.out.println("Invalid amount of Lowercase Characters");
}
else if(specChr<1){
System.out.println("Invalid amount of special Character");
}
else{
System.out.println("Password is Valid");
}
}
}
I have written the working code for password validator. Here is a suggestion for you. If you want to learn how to code efficiently, then you should learn how to work first hard. You have to put more efforts than this. The code you have uploaded is full of syntax errors, at least you can search on the internet for correct syntax, instead of just uploading code here and expecting someone will send you correct code. By this, you won't learn anything.
+ 3
import re
password= input()
x = True
while x:
if (len(password)<7 or len(password)>999):
break
elif not re.search("[a-z]",password):
break
elif not re.search("[0-9]",password):
break
elif not re.search("[!@#$%&*]",password):
break
else:
print("Strong")
x=False
break
if x:
print("Weak")
+ 1
use:
int upprLtr=2;
0
.......thx for the input.....
0
Please find the Code
https://code.sololearn.com/cng1t6r7wstX/#py