Knowee
Questions
Features
Study Tools

Develop a Java program that creates a simple GUI application for a passwordvalidator. The program should allow users to input a password and check ifit meets certain criteria.Requirements:Window with password input, "Check Password" button, result label.Validate password: ≥8 chars, ≥1 uppercase, ≥1 lowercase, ≥1 digit.(7)

Question

Develop a Java program that creates a simple GUI application for a passwordvalidator. The program should allow users to input a password and check ifit meets certain criteria.Requirements:Window with password input, "Check Password" button, result label.Validate password: ≥8 chars, ≥1 uppercase, ≥1 lowercase, ≥1 digit.(7)

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Java program that creates a GUI application for a password validator:

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PasswordValidator {
    private static JTextField passwordField;
    private static JLabel resultLabel;

    public static void main(String[] args) {
        JFrame frame = new JFrame("Password Validator");
        frame.setSize(300, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel();
        frame.add(panel);
        placeComponents(panel);

        frame.setVisible(true);
    }

    private static void placeComponents(JPanel panel) {
        panel.setLayout(null);

        JLabel userLabel = new JLabel("Password:");
        userLabel.setBounds(10, 20, 80, 25);
        panel.add(userLabel);

        passwordField = new JTextField(20);
        passwordField.setBounds(100, 20, 165, 25);
        panel.add(passwordField);

        JButton loginButton = new JButton("Check Password");
        loginButton.setBounds(10, 80, 120, 25);
        panel.add(loginButton);

        resultLabel = new JLabel("");
        resultLabel.setBounds(10, 110, 300, 25);
        panel.add(resultLabel);

        loginButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String password = passwordField.getText();
                if (isValidPassword(password)) {
                    resultLabel.setText("Password is valid.");
                } else {
                    resultLabel.setText("Password is invalid.");
                }
            }
        });
    }

    private static boolean isValidPassword(String password) {
        if (password.length() < 8) {
            return false;
        }
        boolean hasUppercase = !password.equals(password.toLowerCase());
        boolean hasLowercase = !password.equals(password.toUpperCase());
        boolean hasDigit = password.matches(".*\\d.*");

        return hasUppercase && hasLowercase && hasDigit;
    }
}

This program creates a simple GUI with a text field for password input, a "Check Password" button, and a label to display the result. When the button is clicked, it checks if the password meets the criteria (at least 8 characters, at least 1 uppercase letter, at least 1 lowercase letter, and at least 1 digit) and displays the result.

This problem has been solved

Similar Questions

Write a Java program that implements a password validator using a custom exception InvalidPasswordException. The program should have a method validatePassword that takes a string as an argument representing a password and checks its validity based on the following rules: The password should be at least 12 characters long.The password should be a combination of uppercase and lowercase letters, numbers, and symbols.If the password does not meet these criteria, the validatePassword method should throw an InvalidPasswordException with an appropriate error message. Provide 5 sample inputs and their corresponding expected outputs to demonstrate the functionality of the validatePassword method.Expected Output:For a valid password, the output should be "Password is valid."For a password that is too short, the output should be "Invalid Password: Password should be at least 12 characters long."For a password without required characters, the output should be "Invalid Password: Password should be a combination of uppercase and lowercase letters, numbers, and symbols."Sample Input:"Strong@Password123"Sample Output:Password is valid.

Certain authentication system requires the user to enter a password which is an integer. The authentication system should display "Invalid integer. Enter a valid input.",  if the password entered is not a valid integer. This process should be repeated until the user enters a valid integer input. If the password is a valid integer, the authentication system checks if the integer is prime or not. If the password is prime, it displays "Authenticated," otherwise it displays "Unauthenticated”. Write a Java program for the above with proper exception handling.Input-Output Form 1:Enter a valid integer password: 12.3Output:  Invalid integer. Enter a valid input.Enter a valid integer password: 12.7Output: Invalid integer. Enter a valid input.Enter a valid integer password: 12Output: Unauthenticated

Python program to check the validity of username and password input by users

Develop a python function using regular expression for validating a password.Password should contain at least one capital letter, one number and one special character like @$!%*#?&Length of the password should be between 8 and 18.Sample Input:XdsE83&!2Sample Output:ValidSample Input:asDf#$Q$$Invalid

Check if a string is matching password requirements Sample inputProgram#123Sample outputSuccessfully Matched with the Password Requirements.ExplanationRead a string which should satisfy the password requirements.If the string satisfies the given requirements print "Successfully Matched with the Password Requirements." without double quotes.if not satisfied print "Not Matched with the Password Requirements." without the double quotes.Password Requirements :Atleast one Uppercase character.Atleast one Lowercase character.Atleast one special Character.Atleast one Number.The string should be more than 8 characters long. SAMPLE INPUT:  Program#12SAMPLE OUTPUT:Successfully Matched with the Password Requirements.Note:Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.