This post contains a total of 5+ C Sharp Password Validator Program Examples with Source Code. All these programs to Validate Passwords are made using C Sharp.
You can use the source code of these examples with credits to the original owner.
Related Posts
C Sharp Password Validator Programs
1. By Anon Fox
Made by Anon Fox. Password Validator With LinQ and Extension Methods. Source
Hello%$World12 : is Strong Am : is Weak $Still : is Weak
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Tests
{
class Program
{
static void Main(string[] args)
{
string input = @"Hello%$World12";
string input1 = @"Am";
string input2 = @"$Still";
Validate(input);
Validate(input1);
Validate(input2);
}
public static void Validate(string password)
{
string input = Regex.Replace(password, @"\s", "");
if (
input.HasConvenientLength() &&
input.CapturedMatches(@"\W")>= 2 &&
input.CapturedMatches(@"\d")>=2
)
{
Console.WriteLine("{0} : is Strong ",password);
return;
}
Console.WriteLine("{0} : is Weak",password);
}
}
public static class StringExtension
{
public static bool HasConvenientLength(this string input)
{
return input.Length >= 7 ;
}
public static int CapturedMatches(this string input, string pattern)
{
var list = input.Where(c => Regex.IsMatch(c + "", pattern));
return list.Count();
}
}
}
2. By Piotr
Made by Piotr. Simple C Sharp Password validator Program. Source
Password is incorrect Password is incorrect Password is correct
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PasswordValidator
{
class Program
{
static void Main(string[] args)
{
List <string> passwords = new List<string>(){"Password","Password123","$psword1"};
string numbers = "1234567890";
string special = "";
var j = Enumerable.Range(33,70);
foreach(var x in (from int k in j where (k<=48||(k>57&&k<65)) select k).ToList())
{
special+=Convert.ToChar((int)x);
}
foreach(string pass in passwords){
Console.WriteLine((pass.Length>=5&&pass.Length<=10&&(pass.Count(i=>numbers.IndexOf(i)!=-1||special.IndexOf(i)!=-1)>=2)&&(!pass.Contains(' ')))?"Password is correct":"Password is incorrect");
}
}
}
}
3. By Jingga Sona
Made by Jingga Sona. Source
qwerty is not a valid password
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace Sololearn
{
class Program
{
static void Main(string[] args)
{
Regex rgx = new Regex(@"\w\W");
string b = Console.ReadLine();
if (b.Length >= 5 && b.Length <=10){
Console.WriteLine("{0} {1} a valid password",b,rgx.IsMatch(b) ? "is" : "is not");
}
else{
Console.Write("Character Length Must Be Between 5 and 10");
}
}
}
}
4. By Cyrus Ornob Corraya
Made by Cyrus Ornob Corraya. Basic Password validator program. Source
Qwerty123## Valid
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
if(validate (input))
{
Console.WriteLine("Valid");
}
else
{
Console.WriteLine("Invalid") ;
}
}
static bool validate(string pw)
{
if(pw.Length < 8 || pw.Length > 12) return false;
if(pw.Contains("/")) return false;
if(pw.Contains("\\")) return false;
if(pw.Contains(" ")) return false;
string digits = "0123456789";
if(digits.Contains(pw[0])) return false;
bool con_digit = false;
foreach (char d in digits){
if(pw.Contains(d)){ con_digit=true; break;}
}
string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
bool con_uppercase = false;
foreach (char u in uppercase){
if(pw.Contains(u)){ con_uppercase=true; break;}
}
return con_uppercase && con_digit;
}
}
}
5. By Donkey I
Made by Donkey I. Program to checks if the user input is a valid password or not. Source
Pass123 False
using System;
using System.Linq;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string pass = Console.ReadLine();
Console.Write(pass.Any(c => Char.IsDigit(c)) &&
pass.Any(c => "&[email protected]$#%".Contains(c)) &&
pass.Length >= 5 &&
pass.Length <= 10 &&
!pass.Contains(' '));
}
}
}
6. By MR Programmer
Made by MR Programmer. Source
123pass Invalid Password
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
bool cNum=false,cCalpha=false,cAlpha=false,cChar=false,cSnum=false;
var inputPass = Console.ReadLine();
if(inputPass.Length >= 8){
cNum = inputPass.All(char.IsDigit);
cCalpha = inputPass.All(char.IsUpper);
cAlpha = inputPass.All(char.IsLetter);
cChar = inputPass.Contains("\\") || inputPass.Contains(" ") || inputPass.Contains("/");
cSnum = char.IsDigit(inputPass[0]);
if(!cSnum && cCalpha && cAlpha && !cChar && cNum)
Console.WriteLine("Valid Password");
else Console.WriteLine("Invalid Password");
}else Console.WriteLine("Invalid Password Less Than * digit");
}
}
}