@@ -20,10 +20,10 @@ function getPasswordForgeHTML() {
2020 </button>
2121
2222 <div id="rulesContainer" class="rules-container">
23- <p>❌ Must contain at least 8 characters</p>
24- <p>❌ Must contain a number</p>
25- <p>❌ Must contain an uppercase letter</p>
26- <p>❌ Must contain a special character</p>
23+ <p id="rule-length" >❌ Must contain at least 8 characters</p>
24+ <p id="rule-number" >❌ Must contain a number</p>
25+ <p id="rule-upper" >❌ Must contain an uppercase letter</p>
26+ <p id="rule-special" >❌ Must contain a special character</p>
2727 </div>
2828
2929 <div id="passwordResult" class="result-message"></div>
@@ -91,29 +91,47 @@ function initPasswordForge() {
9191 const checkBtn = document . getElementById ( 'checkPasswordBtn' ) ;
9292 const passwordInput = document . getElementById ( 'passwordInput' ) ;
9393 const toggleBtn = document . getElementById ( 'togglePasswordBtn' ) ;
94+
95+ // New: Grab the individual rule DOM elements
96+ const ruleLength = document . getElementById ( 'rule-length' ) ;
97+ const ruleNumber = document . getElementById ( 'rule-number' ) ;
98+ const ruleUpper = document . getElementById ( 'rule-upper' ) ;
99+ const ruleSpecial = document . getElementById ( 'rule-special' ) ;
100+
101+ const result = document . getElementById ( 'passwordResult' ) ;
102+
94103 toggleBtn . addEventListener ( 'click' , ( ) => {
95- if ( passwordInput . type === 'password' ) {
96- passwordInput . type = 'text' ;
97- toggleBtn . textContent = 'Hide' ;
98- } else {
99- passwordInput . type = 'password' ;
100- toggleBtn . textContent = 'Show' ;
101- }
102- } ) ;
104+ if ( passwordInput . type === 'password' ) {
105+ passwordInput . type = 'text' ;
106+ toggleBtn . textContent = 'Hide' ;
107+ } else {
108+ passwordInput . type = 'password' ;
109+ toggleBtn . textContent = 'Show' ;
110+ }
111+ } ) ;
103112
104113 checkBtn . addEventListener ( 'click' , ( ) => {
105- const password = document . getElementById ( 'passwordInput' ) . value ;
106- const result = document . getElementById ( 'passwordResult' ) ;
114+ const password = passwordInput . value ;
107115
116+ // 1. Evaluate Booleans
108117 const hasLength = password . length >= 8 ;
109118 const hasNumber = / \d / . test ( password ) ;
110119 const hasUpper = / [ A - Z ] / . test ( password ) ;
111120 const hasSpecial = / [ ! @ # $ % ^ & * ] / . test ( password ) ;
112121
122+ // 2. Update Individual Rule UI
123+ ruleLength . textContent = hasLength ? '✅ Must contain at least 8 characters' : '❌ Must contain at least 8 characters' ;
124+ ruleNumber . textContent = hasNumber ? '✅ Must contain a number' : '❌ Must contain a number' ;
125+ ruleUpper . textContent = hasUpper ? '✅ Must contain an uppercase letter' : '❌ Must contain an uppercase letter' ;
126+ ruleSpecial . textContent = hasSpecial ? '✅ Must contain a special character' : '❌ Must contain a special character' ;
127+
128+ // 3. Update Global Status
113129 if ( hasLength && hasNumber && hasUpper && hasSpecial ) {
114130 result . textContent = "✅ Strong Password!" ;
131+ result . style . color = 'green' ;
115132 } else {
116133 result . textContent = "❌ Password does not meet all rules!" ;
134+ result . style . color = 'red' ;
117135 }
118136 } ) ;
119- }
137+ }
0 commit comments