Home > Backend Development > C#.Net Tutorial > C# program to check password validity

C# program to check password validity

王林
Release: 2023-08-21 21:17:17
forward
1422 people have browsed it

When creating a password, you may have seen verification requirements on the website, such as the password should be strong and contain the following requirements:

  • minimum of 8 characters, Up to 14 characters
  • At least one lowercase letter
  • No spaces
  • At least one uppercase letter
  • At least one special character

Let’s check these conditions one by one −

Minimum 8 characters, maximum 14 characters

if (passwd.Length < 8 || passwd.Length > 14)
return false;
Copy after login

At least one lowercase letter

if (!passwd.Any(char.IsLower))
return false;
Copy after login

No whitespace

if (passwd.Contains(" "))
return false;
Copy after login

A capital letter

if (!passwd.Any(char.IsUpper))
return false;
Copy after login

Check if there is a special character

string specialCh = @"%!@#$%^&*()?/>.<,:;&#39;\|}]{[_~`+=-" + "\"";
char[] specialCh = specialCh.ToCharArray();
foreach (char ch in specialChArray) {
   if (passwd.Contains(ch))
      return true;
}
Copy after login

The above is the detailed content of C# program to check password validity. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template