Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

by using Java The peoject has to ask the user to enter a password of 8 character

ID: 3701166 • Letter: B

Question

by using Java

The peoject has to ask the user to enter a password of 8 characters and check how much the password is strong (strong, midum, weak) the password has to have at least one digit and one speical characters.

securtity level: (Strong / midum/ weak) nothing majior than that

Client StringHandler +main(args:String[): void +processDigit(char):void +processletter(char):void +processOther(char):void +parse(String):void PasswordSecurityHandler - length:int - digit:Boolean - otherCharacter:boolean +PasswordSe curityHandler() +processDigit(char):void +processLetter(char):void +processOther(char):void +securityLevel():String

Explanation / Answer


import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Surya
*/
public class Bulgarian {
  
//method to find number alphabets...lowercase
static int find_lower(String s)
{
int i=0,n=s.length();
int count=0;
while(i<n)
{
char c= s.charAt(i);
int m = (int)c;
  
if(m>=97 && m<=122)
count++;
i++;
}
return count;
}
  
//method to find number alphabets...uppercase
static int find_upper(String s)
{
int i=0,n=s.length();
int count=0;
while(i<n)
{
char c= s.charAt(i);
int m = (int)c;
  
if(m>=65 && m<=91)
count++;
i++;
}
return count;
}
  
  
//method to find number digits
static int find_digits(String s)
{
int i=0,n=s.length();
int count=0;
while(i<n)
{
char c= s.charAt(i);
int m = (int)c;
  
if(m>=48 && m<=57)
count++;
i++;
}
return count;
}
  
//method to find number special characters
static int find_special(String s)
{
int i=0,n=s.length();
int count=0;
while(i<n)
{
char c= s.charAt(i);
int m = (int)c;
  
if(m>=0 && m<=47)
count++;
else if(m>=58 && m<=64)
count++;
else if(m>=92 && m<=96)
count++;
else if(m>122)
count++;
i++;
}
return count;
}
  
  
  
  
  
//method to check the
public static void check_paswordStrength(String s)
{
  
int l = find_lower(s);
int h = find_upper(s);
int sp = find_special(s);
int d = find_digits(s);
  
  
int sum = l*26 + h *26 + sp* 50 + d *10;///equation to find the strength of the password
  
if(sum<=216)
System.out.println("Password is weak ");
else if(sum>216 && sum<=500)
System.out.println("Password is Medium ");
else
System.out.println("Password is Strong ");
  
}
  
  
public static void main(String argv[])
{
  
String s;
Scanner sc = new Scanner(System.in);
while(true)
{
  
System.out.println("Enter password:(of length 8)");
s =sc.next();
int sp = find_special(s),d = find_digits(s);
if(s.length()<8)
{
System.out.println("Password length should be 8");
}
else if(sp==0 || d==0)
{
System.out.println("Must contain atleast one special character and one digit");
}
else
{
break;
}

  
}
  
check_paswordStrength(s);
}
  
}

output:

run:
Enter password:(of length 8)
alsdf
Password length should be 8
Enter password:(of length 8)
abcdefgh
Must contain atleast one special character and one digit
Enter password:(of length 8)
ab@#sdf8&*%
Password is Medium

BUILD SUCCESSFUL (total time: 32 seconds)