-
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
7 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
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
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
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,4 @@ | ||
export const enum CssClassType { | ||
Text = 'Text', | ||
Background = 'Background', | ||
} |
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,25 @@ | ||
import { CssClassType } from '@enums/cssClassType'; | ||
|
||
export const getClassByStrength = ( | ||
strength: string, | ||
classType: CssClassType | ||
): string => { | ||
const cssPrefix = classType === CssClassType.Text ? 'text' : 'bg'; | ||
|
||
switch (strength) { | ||
case 'Weak': | ||
return `${cssPrefix}-red-500`; | ||
|
||
case 'Moderate': | ||
return `${cssPrefix}-yellow-500`; | ||
|
||
case 'Strong': | ||
return `${cssPrefix}-green-500`; | ||
|
||
case 'Very Strong': | ||
return `${cssPrefix}-green-500`; | ||
|
||
default: | ||
return `${cssPrefix}-red-500`; | ||
} | ||
}; |
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,43 @@ | ||
import { CrackTime } from '@interfaces/crackTime'; | ||
|
||
export const crackTimes: Record<number, CrackTime> = { | ||
8: { | ||
allChars: '28 seconds', | ||
onlyAlphaNum: '2 minutes', | ||
onlyAlpha: '5 minutes', | ||
}, | ||
9: { allChars: '6 hours', onlyAlphaNum: '2 hours', onlyAlpha: '24 minutes' }, | ||
10: { allChars: '2 weeks', onlyAlphaNum: '5 days', onlyAlpha: '21 hours' }, | ||
11: { allChars: '3 years', onlyAlphaNum: '10 months', onlyAlpha: '1 month' }, | ||
12: { allChars: '226 years', onlyAlphaNum: '53 years', onlyAlpha: '6 years' }, | ||
13: { | ||
allChars: '15 thousand years', | ||
onlyAlphaNum: '3 thousand years', | ||
onlyAlpha: '332 years', | ||
}, | ||
14: { | ||
allChars: '1 million years', | ||
onlyAlphaNum: '200 thousand years', | ||
onlyAlpha: '17 thousand years', | ||
}, | ||
15: { | ||
allChars: '77 million years', | ||
onlyAlphaNum: '12 million years', | ||
onlyAlpha: '900 thousand years', | ||
}, | ||
16: { | ||
allChars: '5 billion years', | ||
onlyAlphaNum: '779 million years', | ||
onlyAlpha: '46 million years', | ||
}, | ||
17: { | ||
allChars: '380 billion years', | ||
onlyAlphaNum: '48 billion years', | ||
onlyAlpha: '2 billion years', | ||
}, | ||
18: { | ||
allChars: '26 trillion years', | ||
onlyAlphaNum: '2 trillion years', | ||
onlyAlpha: '126 billion years', | ||
}, | ||
}; |
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,31 @@ | ||
import { CrackTime } from '@interfaces/crackTime'; | ||
|
||
import { crackTimes } from './crackTimes'; | ||
|
||
export const estimateCrackTime = (password: string): string => { | ||
const hasUpper = /[A-Z]/.test(password); | ||
|
||
const hasLower = /[a-z]/.test(password); | ||
|
||
const hasNumbers = /[0-9]/.test(password); | ||
|
||
const hasSpecial = /[!@#$%^&*()_+\-=[\]{}|;:'",.<>?]/.test(password); | ||
|
||
let key: keyof CrackTime = 'onlyAlpha'; | ||
|
||
if (hasUpper && hasLower && hasNumbers && hasSpecial) { | ||
key = 'allChars'; | ||
} else if (hasUpper && hasLower && hasNumbers) { | ||
key = 'onlyAlphaNum'; | ||
} | ||
|
||
const length = password.length; | ||
|
||
if (length > 18) { | ||
return 'Trillions of years'; | ||
} else if (length >= 8 && crackTimes[length]) { | ||
return crackTimes[length][key]; | ||
} | ||
|
||
return 'Not specified'; | ||
}; |
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,5 @@ | ||
export interface CrackTime { | ||
allChars: string; | ||
onlyAlphaNum: string; | ||
onlyAlpha: string; | ||
} |