-
Notifications
You must be signed in to change notification settings - Fork 0
/
Password.java
80 lines (75 loc) · 1.65 KB
/
Password.java
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
74
75
76
77
78
79
80
class Password
{
static int number()
{
return (int)Math.round(Math.random()*9);
}
static char symbol()
{
int i=(int)Math.round(Math.random()*3);
if(i==1)
return '!';
if(i==2)
return '#';
if(i==3)
return '_';
else
return '&';
}
static char upper()
{
int c=1,s=0;
while(c<=3)
{
++c;
s+=(int)Math.round(Math.random()*10);
}
if(s>25)
s=s-5;
return (char)(s+65);
}
static char lower()
{
int c=1,s=0;
while(c<=3)
{
++c;
s+=(int)Math.round(Math.random()*10);
}
if(s>25)
s=s-5;
return (char)(s+97);
}
static int type(char ch)
{
if(Character.isLowerCase(ch))
return 0;
else if(Character.isUpperCase(ch))
return 1;
else if(Character.isDigit(ch))
return 2;
else
return 3;
}
static String cPW()
{
String pw="";
int ch=0;
pw=pw+lower();
while(pw.length()<Length.length())
{
while(type(pw.charAt(pw.length()-1))==ch)
ch=(int)Math.round(Math.random()*3);
if(ch==0)
pw=pw+lower();
if(ch==1)
pw=pw+upper();
if(ch==2)
pw=pw+number();
if(ch==3)
pw=pw+symbol();
//System.out.println(pw);
}
return pw;
}
}