C# strong password checker

This program uses Regex to check whether a password is a strong password. A strong password must be a combination of digits, upper and lower case letters, and symbols. There are four string patterns that need to be created in this problem. The first string pattern is used to match digits. The second string pattern matches upper case letters. The third string pattern matches lower case letters. And the last string pattern will be used to match symbols. You might want to read this page to learn how to write a string pattern: Regular Expression.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions ;
using System.Collections;

namespace Csharpproj
{

  
   class Program
   {
     static void Main(string[] args)
     {
        Console.Write("Enter your password:");
        string string1 = Console.ReadLine();      
        string patdi= @"\d+"; //match digits
        string patupp = @"[A-Z]+"; //match upper cases
        string patlow = @"[a-z]+"; //match lower cases
        string patsym = @"[`~!@$%^&\\-\\+*/_=,;.':|\\(\\)\\[\\]\\{\\}]+"; //match symbols
        Match id=Regex.Match(string1 ,patdi ) ;
        Match upp=Regex.Match(string1,patupp ) ;
        Match low=Regex.Match(string1 ,patlow) ;
        Match sym=Regex.Match(string1 ,patsym ) ;
        if (id.Success && upp.Success && low.Success && sym.Success)
           Console.WriteLine("Strong password!");
        else
           Console.WriteLine("Warning! Your password should be a combination of upper and lower case characters, digits, and symbols. ");
        Console.Read();
     }
   }
}

Posted by: Dara | post date: 02-17-2013 | Subject: C# Programming Language




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.