Password Strength Check
JavaScript
Medium
5 views
Problem Description
Given a password string, print STRONG if it has at least 8 chars and contains at least one lowercase, uppercase, digit, and one special from !@#$%^&*. Otherwise print WEAK.
Input Format
One line password.
Output Format
STRONG or WEAK.
Constraints
Length up to 1e5.
Official Solution
const fs=require('fs');const txt=fs.readFileSync(0,'utf8');const s=txt.replace(/\
?\
$/,'');let lo=false,up=false,di=false,sp=false;for(const ch of s){const c=ch.charCodeAt(0);if(c>=97&&c<=122)lo=true;else if(c>=65&&c<=90)up=true;else if(c>=48&&c<=57)di=true;else if(ch==='!'||ch==='@'||ch==='#'||ch==='$'||ch==='%'||ch==='^'||ch==='&'||ch==='*')sp=true;}const ok=s.length>=8&&lo&&up&&di&&sp;process.stdout.write(ok?'STRONG':'WEAK');
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!