Lex code for password validation
Lex is a computer program that generates lexical analyzers and was written by Mike Lesk and Eric Schmidt. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lex in the C programming language.
Problem: We have to validate password.
A password is correct if it contains:
- Atleast 1 uppercase character
- Atleast 1 lowercase character
- Atleast 1 digit
- Atleast 1 special character
- Minimum 8 characters
Example:
Input: Geeksforgeeks Output: INVALID Input: Geeks@12 Output: VALID
Note: The words can consist of lowercase characters, uppercase characters and digits.
Below is the implementation to count the number of words.
%{ #include<stdio.h> #include<string.h> int a = 0, b=0, c=0, d=0, l=0; %} %% [a-z] {a++;l++;} [A-Z] {b++;l++;} [0-9] {c++;l++;} [$&+, :;=?@#|'<>.-^*()%!] {d++;l++;} . ; %% int yywrap( void ){} int main() { // The function that starts the analysis yylex(); if (a>0 && b>0 && c>0 && d>0 && l>=8) printf ( "VALID\n" ); else printf ( "INVALID\n" ); return 0; } |
Output:
Please Login to comment...