![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to check password validity
While creating a password, you may have seen the validation requirements on a website like a password should be strong and have −
- Min 8 char and max 14 char
- One lower case
- No white space
- One upper case
- One special char
Let us see how to check the conditions one by one −
Min 8 char and max 14 char
if (passwd.Length < 8 || passwd.Length > 14) return false;
Atleast one lower case
if (!passwd.Any(char.IsLower)) return false;
No white space
if (passwd.Contains(" ")) return false;
One upper case
if (!passwd.Any(char.IsUpper)) return false;
Check for one special character
string specialCh = @"%!@#$%^&*()?/>.<,:;'\|}]{[_~`+=-" + "\""; char[] specialCh = specialCh.ToCharArray(); foreach (char ch in specialChArray) { if (passwd.Contains(ch)) return true; }
Advertisements