Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Part02
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
Assessment
Part02
Commits
84d2d7e1
Commit
84d2d7e1
authored
Dec 10, 2018
by
neil.whitehead
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
12:19 10/12/18
parent
8982a5cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
48 deletions
+100
-48
AssessmentPartTwo.java
src/AssessmentPartTwo.java
+100
-48
No files found.
src/AssessmentPartTwo.java
View file @
84d2d7e1
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.util.Arrays
;
import
java.util.Arrays
;
public
class
AssessmentPartTwo
{
public
class
AssessmentPartTwo
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
passwordValidator
(
"lo98passwdiI"
));
}
public
int
scrabbleScore
(
String
aWord
)
public
int
scrabbleScore
(
String
aWord
)
{
{
...
@@ -20,21 +29,25 @@ public class AssessmentPartTwo {
...
@@ -20,21 +29,25 @@ public class AssessmentPartTwo {
aWord
=
aWord
.
toLowerCase
();
//converts string to lowercase
aWord
=
aWord
.
toLowerCase
();
//converts string to lowercase
char
chaWordArr
[]
=
aWord
.
toCharArray
();
//places string into array as ASCII chars
char
chaWordArr
[]
=
aWord
.
toCharArray
();
//places string into array as ASCII chars
for
(
int
i
=
0
;
i
<
chaWordArr
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
chaWordArr
.
length
;
i
++)
{
{
//Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration
if
((
chaWordArr
[
i
]
<
97
)
||
(
chaWordArr
[
i
]
>
122
))
if
((
chaWordArr
[
i
]
<
97
)
||
(
chaWordArr
[
i
]
>
122
))
{
{
continue
;
//Validation: if value is not lowercase letter (ASCII 97 - 122) then skip this iteration
continue
;
}
}
intWordScore
=
intWordScore
+
intScoreArr
[(
chaWordArr
[
i
]-
97
)];
//Char's ASCII code - 97 = Char's position in intScoreArr
intWordScore
=
intWordScore
+
intScoreArr
[(
chaWordArr
[
i
]-
97
)];
//Char's ASCII code - 97 = Char's position in intScoreArr
}
}
return
intWordScore
;
return
intWordScore
;
}
}
public
boolean
passwordValidator
(
String
password
)
public
static
Boolean
passwordValidator
(
String
password
)
//REMEMBER TO TAKE OUT STATIC
{
{
// 04 - Password Validator
// 04 - Password Validator
// Complete this method to validate that the String password
// Complete this method to validate that the String password
...
@@ -45,71 +58,110 @@ public class AssessmentPartTwo {
...
@@ -45,71 +58,110 @@ 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'
boolean
booPasswordUpper
=
false
;
boolean
booUpper
=
false
;
//Uppercase present
boolean
booPasswordLower
=
false
;
boolean
booLower
=
false
;
//Lowercase present
boolean
booPasswordNum
=
false
;
boolean
booNum
=
false
;
//Number present
boolean
booPasswordIsPassword
=
false
;
char
passwordArr
[]
=
password
.
toCharArray
();
char
passwordArr
[]
=
password
.
toCharArray
();
//true == correct, false == incorrect
String
[]
strMustNotContain
=
new
String
[]
{
"password"
,
"passwd"
};
//Password length between 8 and 16 characters
//Password length between 8 and 16 characters
if
(!((
password
.
length
()
>=
8
)
&&
(
password
.
length
()
<=
16
)))
if
((
password
.
length
()
<
8
)
||
(
password
.
length
()
>
16
))
{
{
System
.
out
.
println
(
password
.
length
());
return
false
;
return
false
;
}
}
//Password does not contain. . .
for
(
int
i
=
0
;
i
<
strMustNotContain
.
length
;
i
++)
//selects banned words from array
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for
(
int
i
=
0
;
i
>
passwordArr
.
length
;
i
++)
{
{
System
.
out
.
println
(
passwordArr
[
i
]);
if
((
password
.
toLowerCase
().
contains
(
strMustNotContain
[
i
])))
if
((
passwordArr
[
i
]
>=
48
)
&&
(
passwordArr
[
i
]
<=
57
))
{
{
booPasswordNum
=
tru
e
;
return
fals
e
;
}
}
else
if
((
passwordArr
[
i
]
>=
65
)
&&
(
passwordArr
[
i
]
<=
90
))
//65 to 90 = A to B
}
{
booPasswordUpper
=
true
;
//Password only alphanumeric or !�$%, contains both upper, lower, and numerics
for
(
int
i
=
0
;
i
<
passwordArr
.
length
;
i
++)
{
if
((
passwordArr
[
i
]
>=
48
)
&&
(
passwordArr
[
i
]
<=
57
))
{
//48 to 57 = 0 to 9
booNum
=
true
;
}
}
else
if
((
passwordArr
[
i
]
>=
97
)
&&
(
passwordArr
[
i
]
<=
122
))
// 97 to 122 = a to b
else
if
((
passwordArr
[
i
]
>=
65
)
&&
(
passwordArr
[
i
]
<=
90
))
{
{
//65 to 90 = A to B
booPasswordLower
=
true
;
booUpper
=
true
;
}
else
if
((
passwordArr
[
i
]
>=
97
)
&&
(
passwordArr
[
i
]
<=
122
))
{
// 97 to 122 = a to b
booLower
=
true
;
}
}
else
if
(
passwordArr
[
i
]
==
33
||
passwordArr
[
i
]
==
63
||
passwordArr
[
i
]
==
36
else
if
(
passwordArr
[
i
]
==
33
||
passwordArr
[
i
]
==
63
||
passwordArr
[
i
]
==
36
||
passwordArr
[
i
]
==
37
)
//33 = !, 63 = ?, 36 = $, 37 = %
||
passwordArr
[
i
]
==
37
)
{
{
//33 = !, 63 = ?, 36 = $, 37 = %
}
}
else
//only runs when invalid character is identified
else
{
{
//if Char is not valid
return
false
;
return
false
;
}
}
}
//
if
((
booPasswordUpper
==
true
)
&&
(
booPasswordLower
==
true
)
&&
(
booPasswordNum
==
true
))
{
return
true
;
}
}
else
if
((
booNum
==
false
)
||
(
booUpper
==
false
)
||
(
booLower
==
false
))
{
{
//if password does not contain Num, Upper, or Lower Chars
return
false
;
return
false
;
}
}
//FUCK SAKE. LOOK UP REGEXES.
//FUCK SAKE. LOOK UP REGEXES.
/* Legacy code that I want to keep if I ever look back on this
//str1.toLowerCase().contains(str2.toLowerCase()) if it contains Password.
//for(int i = 0; i < passwordArr.length; i++)
//Password does not contain Password or Passwd
}
for(int i1 = 0; i1 < strMustNotContain.length; i1++)
//selects banned words from array
{
System.out.println("Is " + strMustNotContain[i1].toString() + " in " + password + "?");
for(int i2 = 0; i2 < (passwordArr.length - strMustNotContain[i1].length() + 1); i2++)
{
//cycles through password
char[] comparisonArr = new char[strMustNotContain[i1].length()];
for(int i3 = 0; i3 < strMustNotContain[i1].length(); i3++)
//populates a sample from password which is the same length as banned word
{
comparisonArr[i3] = Character.toLowerCase(passwordArr[i3 + i2]);
//i2 represents the offset of the sample from password, i3 the position within the sample
}
String strComparison = new String(comparisonArr);
//from array to string
System.out.println("Banned word: " + strMustNotContain[i1] + " sample: " + strComparison);
System.out.println(strComparison.equals(strMustNotContain[i1]));
if(strComparison.equals(strMustNotContain[i1]))
//comparison between sample from password to banned word
{
System.out.println("MATCH");
return false;
}
else
{
System.out.println("not a match");
}
}
}
*/
return
true
;
}
}
}
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