-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword.java
More file actions
73 lines (58 loc) · 2.4 KB
/
Copy pathPassword.java
File metadata and controls
73 lines (58 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* This code is my own work. I did not get any help from any online source
such as chegg.com; from a classmate, or any other person other than the instructor
or TA for this course. I understand that getting outside help from this course
other than from the instructor or TA will result in a grade of 0 in this
assignment and other disciplinary actions for academic dishonesty.
# Name : Cristian Z
# Class: CSET 1200
# Instructor: Dr. Jared Oluoch
# Programming Assignment: 3
#Problem: 1
# Date: 09/21/21
# Summary: detect if password has symbol(s) and digit(s)
# WS3Schools gave some help understanding how to check against multiple items at once without using regex from java util by using (.*) to check anything
*/
import java.util.Scanner;
public class Password {
// Check if password is valid or not with a method;
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
//ask user for password;
System.out.print("Please enter a password of at least 10 characters, a digit(s) and with a special symbol(s)(@,#,%,*,!,^): ");
String password1 = input.next();
boolean validPassword = validPassword(password1);
//boolean validPassword(password1);
if(validPassword == true)
{
System.out.println(password1 + " is a valid password, awesome!");
}
else
{
System.out.println("Not quite, please try again");
}
}
public static boolean validPassword(String password1)
{
boolean valid = true;
if (password1.length() >20 || password1.length() < 10)
{
System.out.println("Password must be less than 20 and more than 10 characters in length.");
valid = false;
}
//tell string compressed wise to check against digits in numbers
String numbers = "(.*[0-9].*)";
if (!password1.matches(numbers ))
{
System.out.println("Password must have atleast one number");
valid = false;
}
//check string against symbols
String specialChars = "(.*[@,#,%,*,!,^].*$)";
if (!password1.matches(specialChars ))
{
System.out.println("Password must have atleast one special character among @#$%*!^");
valid = false;
}
return valid;
}
}