Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AssessmentPart2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
norbert.dajnowski
AssessmentPart2
Commits
3f281737
Commit
3f281737
authored
Nov 23, 2018
by
norbertdajnowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit 1
parent
28c76bab
Pipeline
#315
failed with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
3 deletions
+82
-3
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+81
-2
AssessmentPartTwoTest.java
src/AssessmentPartTwoTest.java
+1
-1
No files found.
src/AssessmentPartTwo.java
View file @
3f281737
import
java.util.HashMap
;
import
java.util.Map
;
public
class
AssessmentPartTwo
{
public
class
AssessmentPartTwo
{
...
@@ -13,7 +15,32 @@ public class AssessmentPartTwo {
...
@@ -13,7 +15,32 @@ public class AssessmentPartTwo {
// You will need to come up with a way of connecting each letter to its score and
// You will need to come up with a way of connecting each letter to its score and
// a way of identifying each letter in the word.
// a way of identifying each letter in the word.
return
0
;
int
sumOfWord
=
0
;
for
(
int
i
=
0
;
i
<=
aWord
.
length
()
-
1
;
i
++)
{
//for loop to traverse through each character in the word
switch
(
Character
.
toUpperCase
(
aWord
.
charAt
(
i
)))
{
//switch to the number of points the character gives
case
'E'
:
case
'A'
:
case
'I'
:
case
'O'
:
case
'N'
:
case
'R'
:
case
'T'
:
case
'L'
:
case
'S'
:
case
'U'
:
sumOfWord
=
sumOfWord
+
1
;
break
;
//break applied on switch statement if character points have been successfully added
case
'D'
:
case
'G'
:
sumOfWord
=
sumOfWord
+
2
;
break
;
case
'B'
:
case
'C'
:
case
'M'
:
case
'P'
:
sumOfWord
=
sumOfWord
+
3
;
break
;
case
'F'
:
case
'H'
:
case
'V'
:
case
'W'
:
case
'Y'
:
sumOfWord
=
sumOfWord
+
4
;
break
;
case
'K'
:
sumOfWord
=
sumOfWord
+
5
;
break
;
case
'J'
:
case
'X'
:
sumOfWord
=
sumOfWord
+
8
;
break
;
case
'Q'
:
case
'Z'
:
sumOfWord
=
sumOfWord
+
10
;
break
;
}
}
return
sumOfWord
;
//returns the points added up for each character in the word
}
}
...
@@ -28,7 +55,59 @@ public class AssessmentPartTwo {
...
@@ -28,7 +55,59 @@ public class AssessmentPartTwo {
// - has at least one lower case letter, one upper case letter and a number
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
// - does not contain the phrases 'password' or 'passwd'
return
false
;
int
validChars
=
0
;
boolean
lwrCase
=
false
;
boolean
upperCase
=
false
;
//set of variables to determine if password is valid
boolean
num
=
false
;
if
((
password
.
length
()
<
8
)
||
(
password
.
length
()
>
16
)){
return
false
;
//if password is inappropriate length then return false (invalid)
}
if
((
password
.
toLowerCase
().
contains
(
"password"
)
==
true
)
||
(
password
.
toLowerCase
().
contains
(
"passwd"
)
==
true
))
{
return
false
;
//if password contains "password", "passwd" or "pass" then return false(invalid)
}
for
(
int
i
=
0
;
i
<=
password
.
length
()
-
1
;
i
++)
{
//iterates through every character in password
if
((
password
.
charAt
(
i
)
>
96
)
&&
(
password
.
charAt
(
i
)
<
123
)){
lwrCase
=
true
;
validChars
++;
//checks if a lower case char exists, iterates validChars
}
if
((
password
.
charAt
(
i
)
>
64
)
&&
(
password
.
charAt
(
i
)
<
91
))
{
upperCase
=
true
;
validChars
++;
//checks if an upper case char exists, iterates validChars
}
if
((
password
.
charAt
(
i
)
>
47
)
&&
(
password
.
charAt
(
i
)
<
58
))
{
num
=
true
;
validChars
++;
//checks if a number char exists, iterates validChars
}
if
((
password
.
charAt
(
i
)
==
''
)
||
(
password
.
charAt
(
i
)
==
'!'
)
||
(
password
.
charAt
(
i
)
==
'$'
)
||
(
password
.
charAt
(
i
)
==
'%'
))
{
validChars
++;
//iterates validChars if the special characters in if statement are used
}
//validChars is compared to password length in the end to check if all characters have matched the validation criteria
}
if
((
validChars
==
password
.
length
())
&&
(
num
==
true
)
&&
(
upperCase
==
true
)
&&
(
lwrCase
==
true
))
{
return
true
;
//returns password as valid if all of the characters are valid and meet the requirements stated
}
return
false
;
// password must be invalid if this part of the code is reached
}
}
}
}
src/AssessmentPartTwoTest.java
View file @
3f281737
...
@@ -37,7 +37,7 @@ class AssessmentPartTwoTest {
...
@@ -37,7 +37,7 @@ class AssessmentPartTwoTest {
"a88drTcdmn45tdgjhj,false"
,
"a88drTcdmn45tdgjhj,false"
,
"pmmfj6793,false"
,
"pmmfj6793,false"
,
"PASSWORD,false"
,
"PASSWORD,false"
,
"lo98passiI,false"
,
"lo98pass
wd
iI,false"
,
"oi!Fcv98ij,true"
"oi!Fcv98ij,true"
})
})
void
testPasswordValidator
(
String
thePassword
,
Boolean
expectedResult
)
{
void
testPasswordValidator
(
String
thePassword
,
Boolean
expectedResult
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment