Password Strength Check with Simple Rules

Dart app to check password strength using simple rules: length, uppercase, lowercase, numbers, and special characters. Ready for console or Flutter.

Brief Introduction

Password Strength Check with Simple Rules (dart)
DESCRIPTION:
A Dart application that checks the strength of a password based on simple rules: minimum length, presence of uppercase letters, lowercase letters, numbers, and special characters. The code is ready to use and easily extendable.

ADDITIONAL NOTES:
This example is completely standalone and requires no external libraries. It is ideal for console applications or integration in Flutter apps for client-side validation.

EXPLANATIONS:
- The `validaPassword` function checks that the password meets all defined rules: minimum length, presence of at least one uppercase letter, one lowercase letter, one number, and one special character.
- Regular expressions are used to check for the presence of different character types.
- The main function provides password examples and prints the validation result for each.
- The code is commented in Italian to facilitate understanding and maintenance.

Example Code: dart

// Password Strength Check with Simple Rules

// Constants for validation rules configuration
const int lunghezzaMinima = 8;

// Function that checks if the password is valid according to the defined rules
bool validaPassword(String password) {
  // Minimum length check
  if (password.length < lunghezzaMinima) {
    return false;
  }

  // Regular expressions for various checks
  final RegExp maiuscola = RegExp(r'[A-Z]');
  final RegExp minuscola = RegExp(r'[a-z]');
  final RegExp numero = RegExp(r'[0-9]');
  final RegExp carattereSpeciale = RegExp(r'[!@#\$%\^&\*(),.?":{}|<>]');

  // Check for at least one uppercase letter
  if (!maiuscola.hasMatch(password)) {
    return false;
  }

  // Check for at least one lowercase letter
  if (!minuscola.hasMatch(password)) {
    return false;
  }

  // Check for at least one number
  if (!numero.hasMatch(password)) {
    return false;
  }

  // Check for at least one special character
  if (!carattereSpeciale.hasMatch(password)) {
    return false;
  }

  // If all conditions are met, the password is valid
  return true;
}

void main() {
  // Password examples to test
  List<String> passwordDiTest = [
    'Password1!',      // valid
    'password1!',      // missing uppercase
    'PASSWORD1!',      // missing lowercase
    'Password!',       // missing number
    'Password1',       // missing special character
    'Pass1!',          // too short
    'P@ssw0rd2024'     // valid
  ];

  // Test loop and print results
  for (var pwd in passwordDiTest) {
    bool risultato = validaPassword(pwd);
    print('Password: "$pwd" is valid? ${risultato ? 'Yes' : 'No'}');
  }
}
×
×
×
Do you want to regenerate the answer?
×
Export chat
Choose export format
Generazione PDF in corso…
Allegati
×
You are about to close the chat and switch to the image generator. If you are not logged in, you will lose our chat. Do you confirm?
You are viewing a shared chat in temporary mode. It will not be saved.
×
Saved prompts
×
Private note
×
Label
×
Search all chats
×
Your insights
Analyzing…
×
AI Preferences
Assistant name 30
Answer length
AI model
Structured answers
Include examples
Use emojis
Guide me, don't solve Hints and questions instead of a ready answer
More settings →
×
Share this chat
Anyone opening this link can view the chat or add it to their profile as their own chat.
Note: the chat attachments will be shared too. Anyone who adds it will receive a copy of the files in their own folder.
Shared chat
Someone shared a chat with you. Do you want to just view it or add it to your chats?
Note: the chat attachments will be shared too. Anyone who adds it will receive a copy of the files in their own folder.
×

Saved messages

Loading...

×

Chat History

example-programs · CHAT HISTORY

Loading...

AI Preferences

×
  • BasicQuick and essential answers for study
  • MediumHigher quality for study and programming
  • AdvancedComplex reasoning and detailed analysis
Explain Steps

What do you need?

Software: Dart SDK (version 2.12 or higher for null safety support)

No external dependencies required

Main function `validaPassword` that accepts a string and returns a boolean

Configuration: validation rules defined as constants at the beginning of the code

Arduino: not applicable in this example (Dart software only)