-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPassMan.java
More file actions
125 lines (123 loc) · 3.87 KB
/
PassMan.java
File metadata and controls
125 lines (123 loc) · 3.87 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
package org.millardps.InventoryManagement;
import java.util.*;
import java.io.*;
public class PassMan{
private File p= new File("pmem.txt");
private File m= new File("mem.txt");
private String newPass;
private String verPass;
private String oldPass;
private boolean cn;
private Scanner scanner=new Scanner(System.in);
private Scanner scanner2=new Scanner(System.in);
String letters[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","~","`","!","@","#","$","%","^","&","*","_","-","=","+","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," "};
String shifted[]={"m","l","8","q","A","P","R","W","C","h","n","k","1","7","z","B","o","9","2","g","f","6","p","O","0","a","e","3","j","Q","V","-","4","=","b","d","J","N"," ","X","","M","I","U","J","i","5","y","c","w","*","T","$","%","S","v","^","L","+","&","Y","u","#","D","_","","r","Z","H","!","s","@","F","t","x","G","E"};
private boolean resettting;
PassMan(){
if (! p.exists()){
if(m.exists()){
System.out.println("Tampering detected...");
System.out.println("Clearing Inventory...");
m.delete();
System.out.println("Inventory Cleared.");
}
System.out.print("Welcome to Oxi Inventory Management! Please set a password. This can be changed at any time with the 'passwd' command.");
try{
PrintWriter pWrite= new PrintWriter("pmem.txt","UTF-8");
while (true){
System.out.println("Please create your password!");
newPass=scanner.nextLine();
System.out.println("Please verify your password!");
verPass=scanner2.nextLine();
for(int i=0;i<newPass.length();i++){
if (Arrays.stream(letters).anyMatch(newPass.substring(i)::equals)){
cn=true;
}
else{
cn=false;
}
}
if (newPass.equals(verPass) && cn){
pWrite.println(encode(newPass));
pWrite.close();
try{
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
catch(InterruptedException e){
System.out.println("InterruptedException");
}
catch(IOException e){
System.out.println("IOException");
}
Console console=new Console();
break;
}
}
}
catch (IOException e){
System.out.println("IO Exception.");
}
}
else if (p.exists()){
try{
Scanner scanner3=new Scanner(new File("pmem.txt"));
System.out.println("Welcome back to Oxi Inventory Management! Please enter your password!");
oldPass=scanner.nextLine();
String readPass=decode(scanner3.nextLine());
if (oldPass.equals(readPass)){
try{
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
catch(InterruptedException e){
System.out.println("InterruptedException");
}
catch(IOException e){
System.out.println("IOException");
}
Console console=new Console();
}
else{
System.out.println("Password Incorrect.");
}
}
catch(FileNotFoundException e){
System.out.println("Password does not exist.");
}
}
}
public String encode(String msg){
String output="";
for(int x=0;x<msg.length();x++){
output+=shifted[indexOf(letters,msg.substring(x,x+1))];
}
return output;
}
public String decode(String msg){
String output="";
for(int x=0;x<msg.length();x++){
output+=letters[indexOf(shifted,msg.substring(x,x+1))];
}
return output;
}
/**public String decode(String msg2){
String output = "";
for(int x = 0; x < msg2.length(); x++){
char ch = (char)(msg2.charAt(x) - 7);
if (ch > 'z')
output += (char)(msg2.charAt(x) - (19));
else
output += ch;
}
return output;
}**/
public int indexOf(String array[], String value){
int index = -1;
for (int i=0;i<array.length;i++) {
if (array[i].equals(value)) {
index = i;
break;
}
}
return index;
}
}