Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Assessment Part Two
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
william.leather
Assessment Part Two
Commits
226c2c7d
Commit
226c2c7d
authored
Dec 31, 2018
by
will
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
assessment 2
parent
01df26df
Pipeline
#561
failed with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
3 deletions
+98
-3
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+98
-3
No files found.
src/AssessmentPartTwo.java
View file @
226c2c7d
import
java.util.regex.Pattern
;
public
class
AssessmentPartTwo
{
...
...
@@ -13,7 +14,63 @@ public class AssessmentPartTwo {
// 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.
return
0
;
int
finalresult
=
0
;
int
i
=
0
;
while
(
i
<
aWord
.
length
()-
1
);
//initiates the loop until the condition is false, to check every single character of the word
{
char
letter
=
aWord
.
charAt
(
i
);
//letter receives the character from the word, in position i, and treats it similar to an array.
if
((
letter
==
'a'
)
||
(
letter
==
'e'
)
||
(
letter
==
'i'
)
||
(
letter
==
'o'
)
||
(
letter
==
'n'
)
||
(
letter
==
'r'
)
||
(
letter
==
't'
)
||
(
letter
==
'l'
)
||
(
letter
==
's'
)
||
(
letter
==
'u'
))
{
finalresult
=
finalresult
+
1
;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 1 point
}
else
if
((
letter
==
'd'
)||(
letter
==
'g'
))
{
finalresult
=
finalresult
+
2
;
//this goes through these 2 letters mentioned and if the word has EITHER of them in it,
//it will give 2 points
}
else
if
((
letter
==
'b'
)||(
letter
==
'c'
)||(
letter
==
'm'
)||(
letter
==
'p'
))
{
finalresult
=
finalresult
+
3
;
//this will search through the letters mentioned and if the word has ANY of them in it,
//it will give 3 points
}
else
if
((
letter
==
'f'
)||(
letter
==
'h'
)||(
letter
==
'v'
)||(
letter
==
'w'
)||(
letter
==
'y'
))
{
finalresult
=
finalresult
+
4
;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 4 points
}
else
if
(
letter
==
'k'
)
{
finalresult
=
finalresult
+
5
;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 5 points
}
else
if
((
letter
==
'j'
)||(
letter
==
'x'
))
{
finalresult
=
finalresult
+
8
;
//this if goes through all the letters mentioned and if the word has ANY of them in it,
//it will give 8 points
}
else
if
((
letter
==
'q'
)
||
(
letter
==
'z'
))
{
finalresult
=
finalresult
+
10
;
//this will search through letters mentioned and if the word has ANY of them in it,
//it will give 10 points
}
i
++;
//goes through to the next letter in the word until it reaches the last letter
}
return
finalresult
;
//returns the total points for the word
}
...
...
@@ -24,11 +81,49 @@ public class AssessmentPartTwo {
// is a valid password
// A password is valid if it is
// - between 8 and 16 characters long (inclusive)
// - made up of letters (upper or lower), numbers, and the following characters !
£
$%
// - made up of letters (upper or lower), numbers, and the following characters !
�$%
// - has at least one lower case letter, one upper case letter and a number
// - does not contain the phrases 'password' or 'passwd'
return
false
;
Pattern
specialCharPatten
=
Pattern
.
compile
(
"[^a-z0-9 ]"
,
Pattern
.
CASE_INSENSITIVE
);
Pattern
UpperCasePatten
=
Pattern
.
compile
(
"[A-Z ]"
);
Pattern
lowerCasePatten
=
Pattern
.
compile
(
"[a-z ]"
);
Pattern
digitCasePatten
=
Pattern
.
compile
(
"[0-9 ]"
);
//uses the java.util.regex.Pattern from java where it compares every letter of the password
//uses the java.util.regex.Pattern from java to search for upper case
//uses the java.util.regex.Pattern from java to search for lower case
//uses the java.util.regex.Pattern from java to search for numbers and special characters
boolean
flag
=
true
;
//turn the final result into a boolean variable to use in every condition
if
((
password
.
length
()
<
8
)
&&
(
password
.
length
()
>
16
))
{
flag
=
false
;
//check if password is between 8-16 characters inclusive if not returns false
}
if
(!
specialCharPatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search for any special characters and also special words in it for example password
//if not returns false
}
if
(!
UpperCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search if password contains upper case if not returns false
}
if
(!
lowerCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search if password contains lower case if not returns false
}
if
(!
digitCasePatten
.
matcher
(
password
).
find
())
{
flag
=
false
;
//search if password contains any numbers, if not returns false
}
return
flag
;
//returns the final result if password is valid or not
}
}
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