-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUser.java
More file actions
133 lines (125 loc) · 4.04 KB
/
User.java
File metadata and controls
133 lines (125 loc) · 4.04 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import java.math.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class User extends Person{
String username;
String password;
int authorization;
public User(String string, String string2, int i, String string3, int j, String string4, int k,
String string5) {
super(string3, j, string4, k, string5);
// TODO Auto-generated method stub
username = string;
password = hash(string2);
authorization = i;
}
public User(String usn,String pwd, int auth, String n, int a, String sx, long aad, String addr )
{
super( n, a, sx, aad, addr );
username = usn;
authorization = auth;
password = hash(pwd);
}
public User(String usn,String pwd, int auth)
{
super();
username = usn;
authorization = auth;
password = hash(pwd);
}
public String hash(String plaintext)
{
MessageDigest m;
try {
m = MessageDigest.getInstance("MD5");
m.reset();
m.update(plaintext.getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while(hashtext.length() < 32 ){
hashtext = "0"+hashtext;
}
return hashtext;
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "error";
}
public String getusn()
{
return username;
}
public String getpwd()
{
return password;
}
public int getauth()
{
return authorization;
}
public void modify(int a, String y)
{
switch(a)
{
case 1: username = y;
break;
case 2: password = hash(y);
break;
case 3: authorization = Integer.parseInt(y);
break;
}
}
/*public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("\t\t\t\t\t _______ __ __ _ \r\n"
+ "\t\t\t\t\t |__ __| / _|/ _(_) \r\n"
+ "\t\t\t\t\t | |_ __ __ _| |_| |_ _ ___ \r\n"
+ "\t\t\t\t\t | | '__/ _` | _| _| |/ __| \r\n"
+ "\t\t\t\t\t | | | | (_| | | | | | | (__ \r\n"
+ "\t\t\t\t\t |_|_| \\__,_|_| |_| |_|\\___| _ \r\n"
+ "\t\t\t\t\t (_) | (_) \r\n"
+ "\t\t\t\t\t _ __ ___ ___ _ __ _| |_ ___ _ __ _ _ __ __ _ \r\n"
+ "\t\t\t\t\t | '_ ` _ \\ / _ \\| '_ \\| | __/ _ \\| '__| | '_ \\ / _` | \r\n"
+ "\t\t\t\t\t | | | | | | (_) | | | | | || (_) | | | | | | | (_| | \r\n"
+ "\t\t\t\t\t |_|_|_| |_|\\___/|_| |_|_|\\__\\___/|_| |_|_| |_|\\__, | \r\n"
+ "\t\t\t\t\t / ____| | | __/ | \r\n"
+ "\t\t\t\t\t | (___ _ _ ___| |_ ___ _ __ ___ |___/ \r\n"
+ "\t\t\t\t\t \\___ \\| | | / __| __/ _ \\ '_ ` _ \\ \r\n"
+ "\t\t\t\t\t ____) | |_| \\__ \\ || __/ | | | | | \r\n"
+ "\t\t\t\t\t |_____/ \\__, |___/\\__\\___|_| |_| |_| \r\n"
+ "\t\t\t\t\t __/ | \r\n"
+ "\t\t\t\t\t |___/ ");
String a,b;
System.out.println("get u name");
a = s.nextLine();
System.out.println("get p");
b = s.nextLine();
if(a.length()>=6)
{
/*call function in login to check if uname exists*/
/*if it does, ask again. make the
* uname checking in array list as the cond
* for the while loop and keep asking for it.*
if(b != null)
{
// Matcher m = p.matcher(b);
// if(m.matches())
if(b.length()>=8)
{
User u1 = new User(a,b,0);
System.out.println(u1.getpwd());
}
else System.err.print("no <3");
}
else System.err.print("no <3");
}
else System.err.print("no <3");
}*/
}