0% found this document useful (0 votes)
4 views8 pages

TY3 - 05 - A - CSS - Exp - 01

The document describes the implementation of a Password Strength Checker using Java Swing, which evaluates the strength of a password based on various criteria such as length, character variety, and complexity. The program features a graphical user interface that displays the password strength as 'Strong', 'Medium', or 'Weak' with corresponding warnings. The conclusion highlights the effectiveness of the checker in helping users create secure passwords.

Uploaded by

Hansal Bhangale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

TY3 - 05 - A - CSS - Exp - 01

The document describes the implementation of a Password Strength Checker using Java Swing, which evaluates the strength of a password based on various criteria such as length, character variety, and complexity. The program features a graphical user interface that displays the password strength as 'Strong', 'Medium', or 'Weak' with corresponding warnings. The conclusion highlights the effectiveness of the checker in helping users create secure passwords.

Uploaded by

Hansal Bhangale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

EXPERIMENT NO:- 01

NAME:- Vanshika Nitin Bedmutha


CLASS:- TY-03
BATCH:- A
ROLL NO: 05
SUBJECT:-
CSS

AIM:-Implement a password strength checker that evaluates the strength of a given password
based on several security criteria.

PROGRAM:-
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.regex.*;

public class PasswordStrengthChecker {

public static void main(String[] args) {


// Create the main frame for the GUI
JFrame frame = new JFrame("Password Strength Checker");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 300);

// Create the panel to hold components


JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3, 2, 10, 10));

// Create the labels and text fields


JLabel passwordLabel = new JLabel("Enter Password:");
JPasswordField passwordField = new JPasswordField();
JLabel strengthLabel = new JLabel("Password Strength:");

// Create a label to display password strength


JLabel resultLabel = new JLabel(" ");
resultLabel.setFont(new Font("Arial", Font.BOLD, 14));

// Add components to the panel


panel.add(passwordLabel);
panel.add(passwordField);
panel.add(strengthLabel);
panel.add(resultLabel);
// Add panel to the frame
frame.add(panel);

// Create the "Check Strength" button


JButton checkButton = new JButton("Check Strength");
panel.add(checkButton);

// Add action listener to the button to check password strength


checkButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Get the entered password
String password = new String(passwordField.getPassword());

// Check password strength


String strength = checkPasswordStrength(password);

// Update the result label with the password strength


resultLabel.setText(strength);
updateStrengthLabel(strength, resultLabel);
}
});

// Set the frame visible


frame.setVisible(true);
}

// Method to check password strength


public static String checkPasswordStrength(String password) {
if (password.length() < 8) {
return "Weak: Too short (min 8 characters)";
}

boolean hasUpperCase = false;


boolean hasLowerCase = false;
boolean hasDigit = false;
boolean hasSpecialChar = false;

// Check each character of the password


for (int i = 0; i < password.length(); i++) {
char c = password.charAt(i);
if (Character.isUpperCase(c)) {
hasUpperCase = true;
} else if (Character.isLowerCase(c)) {
hasLowerCase = true;
} else if (Character.isDigit(c)) {
hasDigit = true;
} else if (!Character.isLetterOrDigit(c)) {
hasSpecialChar = true;
}
}

// Evaluate password strength based on criteria


if (hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar) {
return "Strong";
} else if ((hasUpperCase || hasLowerCase) && hasDigit) {
return "Medium";
} else {
return "Weak: Include uppercase, lowercase, digit, and special
character.";
}
}

// Method to update strength label based on result


private static void updateStrengthLabel(String strength, JLabel label)
{
if (strength.equals("Strong")) {
label.setForeground(Color.GREEN);
} else if (strength.equals("Medium")) {
label.setForeground(Color.ORANGE);
} else {
label.setForeground(Color.RED);
}
}
}
OUTPUT:-
● GUI of Password Strength Checker

● Password Strength Checker indicating Password Strength as “Strong”

● Password Strength Checker indicating Password Strength as “Medium”


● Password Strength Checker indicating Password Strength as “Weak” and giving
a warning of including “Uppercase”

● Password Strength Checker indicating Password Strength as “Weak” and giving


a warning of password being “Too Short”
Review Questions:
Conclusion:In conclusion, we have successfully implemented a password strength checker to
help users create strong and secure passwords. By evaluating passwords based on criteria
such as length, complexity, the inclusion of uppercase and lowercase letters, numbers, special
characters, and the avoidance of common words or sequences, the checker can effectively
assess password strength.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy