SWS Experiment no 5
Aim- To Design and implement a program for adding passwords to a file.
The program should be able to filter out weak passwords (based on dictionary words or variants) and store the strong passwords by creating a hash of user ID and password.
output
import java.util.*;
import
java.lang.String;
import
java.lang.Character;
public class
CheckingPassword {
public static void
main(String[] args) {
Scanner
input = new Scanner(System.in);
System.out.print("Please enter a Password: ");
String
password = input.next();
if
(isValid(password)) {
System.out.println("Valid Password");
} else {
System.out.println("Invalid Password");
}}
public static
boolean isValid(String password) {
if
(password.length() < 8) {
return
false;
} else {
char c;
int
count = 1;
for (int
i = 0; i < password.length() - 1; i++) {
c =
password.charAt(i);
if
(!Character.isLetterOrDigit(c)) {
return false;
}
else if (Character.isDigit(c)) {
count++;
if (count < 2) {
return false;
} } } }
return true;
} }
OUTPUT
C:\Users\MGMCET
IT\Documents>javac CheckingPassword.java
C:\Users\MGMCET
IT\Documents>java CheckingPassword
Please enter a
Password: vardhan
Invalid Password
C:\Users\MGMCET
IT\Documents>java CheckingPassword
Please enter a
Password: vardhaN456
Valid Password
C:\Users\MGMCET
IT\Documents>java CheckingPassword
Please enter a
Password:
Click here to download
SWS Experiment no 5
Reviewed by Akshay Salve
on
12:59 PM
Rating:
No comments: