Repository navigation
London | 26-ITP-May | Russom Gebremeskel | Sprint 3 | Coursework Stretch #1746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
301ea63
2501561
63e477b
a8e1b2d
9e2cef8
2ba2e34
06d5f91
3dc6da6
1e6cb55
61b2ce7
0407869
06d3f9a
598f744
e6fde3b
c2f743c
e7ff9c7
751fb78
4707f5a
f504687
d9197c4
9494c3d
582699c
b806b41
fcf27e7
04f544f
4815e87
9dc9e1f
10b0d0f
cccf002
ed2729e
4fa3e6c
ea5fa0f
6102a89
717584d
fed8ddd
bb815ef
c8fc9dd
3a565e9
c80ed87
38c28b3
f12c635
48b8dae
d5091de
fa07e40
71c6ea1
c12bed8
1b777bf
5d29d04
63905f0
be0c56e
f05ab1d
d6e7d06
2431fdf
7421372
51a7234
7465a37
b5ed6ae
d363d13
bd5de48
616bbbf
2de2d40
05f3e6e
ba2ebd0
52f6943
f950077
0c5efc1
3e016dc
8cde26f
db81678
0aede1c
9140665
b627dd7
3df0769
9a77853
62a181f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,16 @@ | ||
| export function isValidPassword(password) { | ||
| return password.length >= 5; | ||
| export function isValidPassword(password, previousPasswords = []) { | ||
| if (previousPasswords.includes(password)) { | ||
| return false; | ||
| } | ||
| if (password.length < 5) { | ||
| return false; | ||
| } | ||
|
|
||
| for (const char of password) { | ||
| if (!/[A-Z]/.test(password)) return false; | ||
| if (!/[a-z]/.test(password)) return false; | ||
| if (!/[0-9]/.test(password)) return false; | ||
| if (!/[!#$%.*&]/.test(password)) return false; | ||
| } | ||
|
Comment on lines
+9
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a dead code that I forgot to delete from previous attempt to solve the problesm. |
||
| return true; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,53 @@ You must breakdown this problem in order to solve it. Find one test case first a | |
| */ | ||
| import { isValidPassword } from "./password-validator.js"; | ||
| test("password has at least 5 characters", () => { | ||
| // Arrange | ||
| const password = "12345"; | ||
| // Act | ||
| const result = isValidPassword(password); | ||
| // Assert | ||
| expect(result).toEqual(true); | ||
| } | ||
| ); | ||
| // Arrange | ||
| const password = "Az9!"; | ||
| // Act | ||
| const result = isValidPassword(password); | ||
| // Assert | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| // Have at least one English uppercase letter (A-Z) | ||
| test("password has at least uppercase letter", () => { | ||
| const password = "1az9!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| // Have at least one English lowercase letter (a-z) | ||
| test("password has at least lowercase letter", () => { | ||
| const password = "1AZ9!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| // Have at least one number (0-9) | ||
| test("password has at least one number (0-9)", () => { | ||
| const password = "Aazc!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| // Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&") | ||
| test("password has at least non-alphanumeric symbols", () => { | ||
| const password = "1Az99"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
|
||
| // Must not be any previous password in the passwords array. | ||
| test("password must not be any previous password in the passwords array", () => { | ||
| const password = "1Az9!"; | ||
| const previousPassword = ["1Az9!", "1HBz2!"]; | ||
| const result = isValidPassword(password, previousPassword); | ||
| expect(result).toEqual(false); | ||
| }); | ||
|
Comment on lines
+56
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the function return
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I changed the test to (true) and it fails. |
||
|
|
||
| // Valid password returns true. | ||
| test("valid password returns true", () => { | ||
| const password = "1Az9!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(true); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index++does not "check the next characterstr". Could you rephrase the statement?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index++ increments by 1 each time the lope find a match?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That still does not quite explain "why" it is being used in the code.