-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
19 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/test/java/chap02/PasswordStrength.java → src/main/java/chap02/PasswordStrength.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package chap02; | ||
|
||
public enum PasswordStrength { | ||
NORMAL, STRONG | ||
WEAK, INVALID, NORMAL, STRONG | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package chap02; | ||
|
||
public class PasswordStrengthMeter { | ||
public PasswordStrength meter(String s) { | ||
if(s == null || s.isEmpty()) return PasswordStrength.INVALID; // 값이 없는 경우 | ||
int metCounts = getMetCriteriaCounts(s); | ||
if(metCounts <= 1) return PasswordStrength.WEAK; | ||
if(metCounts == 2) return PasswordStrength.NORMAL; | ||
return PasswordStrength.STRONG; | ||
} | ||
|
||
private int getMetCriteriaCounts(String s) { | ||
int metCounts = 0; | ||
if(s.length() >= 8) metCounts++; // 길이가 8글자 이상인 조건만 충족하는 경우 | ||
if(meetsContainingNumberCriteria(s)) metCounts++; // 숫자를 포함하지 않고 나머지 조건은 충족하는 경우 | ||
if(meetsContainingUppercaseCriteria(s)) metCounts++; // 대문자를 포함하지 않고 나머지 조건을 충족시킬 경우 | ||
return metCounts; | ||
} | ||
|
||
private boolean meetsContainingUppercaseCriteria(String s) { | ||
for(char ch : s.toCharArray()){ | ||
if(Character.isUpperCase(ch)){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private boolean meetsContainingNumberCriteria(String s) { | ||
for(char ch : s.toCharArray()){ | ||
if(ch >= '0' && ch <='9'){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters