-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayPasswordsController.java
More file actions
143 lines (120 loc) · 4.59 KB
/
DisplayPasswordsController.java
File metadata and controls
143 lines (120 loc) · 4.59 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
134
135
136
137
138
139
140
141
142
143
package PasswordManagerGUI;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.text.Text;
import java.io.*;
import java.math.BigInteger;
import java.util.ArrayList;
import static PasswordManagerGUI.LoginScreenController.getLogin;
import static PasswordManagerGUI.LoginScreenController.getPassword;
public class DisplayPasswordsController {
String name = "";
String help0 = "";
String help = "";
String help1 = "";
String decrypted = "";
BigInteger help2;
BigInteger help3;
BigInteger[] encryption;
ArrayList<BigInteger> decryption = new ArrayList();
String login = getLogin();
String password = getPassword();
BigInteger d;
Encryption bob = new Encryption();
@FXML
private ImageView loginNew;
@FXML
private MenuItem author;
@FXML
private Button newAccountBtn;
@FXML
private Button displayBtn;
@FXML
private Text text;
@FXML
private TextField newWebpage;
@FXML
private TextField newLogin;
@FXML
private PasswordField passwordNew;
@FXML
private Text authorMark;
@FXML
void addNewAccount(ActionEvent event) {
//System.out.println("Name of the webpage");
name = newWebpage.getText();
name += "\n";
name += newLogin.getText();
name += "\n";
name += passwordNew.getText();
name += "\n";
try {
BufferedWriter fileKey = new BufferedWriter(new FileWriter("publickey.txt", true));
BufferedWriter filePswd = new BufferedWriter(new FileWriter("passwords.txt", true));
BufferedReader readKey = new BufferedReader(new FileReader("publickey.txt"));
BufferedReader readPswd = new BufferedReader(new FileReader("passwords.txt"));
help = readKey.readLine();
help2 = new BigInteger(help);
help3 = help2.modInverse(FileIO.result);
encryption = bob.encrypt(name, help2, FileIO.result);
for (int i = 0; i < encryption.length; i++)
filePswd.write(encryption[i] + "\t" + "");
filePswd.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
void display(ActionEvent event) {
try {
text.setText("");
BufferedWriter fileKey = new BufferedWriter(new FileWriter("publickey.txt", true));
BufferedWriter filePswd = new BufferedWriter(new FileWriter("passwords.txt", true));
BufferedReader readKey = new BufferedReader(new FileReader("publickey.txt"));
BufferedReader readPswd = new BufferedReader(new FileReader("passwords.txt"));
d = LoginScreenController.getD();
help0 = readKey.readLine();
while (true) {
help = readPswd.readLine();
if (help == null)
break;
int pom1 = 0; //poczatek liczby
for (; ; ) {
pom1 = help.indexOf("\t");
//System.out.println(pom1+" "+help.length());
if (pom1 == -1)
break;
help1 = help.substring(0, pom1);
help2 = new BigInteger(help1);
decryption.add(help2);
help = help.substring(pom1 + 1, help.length());
//System.out.println(decryption);
}
for (int i = 0; i < decryption.size(); i++) {
if (bob.decrypt(decryption.get(i), d, FileIO.result) == "\n") {
decrypted = "\n";
}
decrypted += (bob.decrypt(decryption.get(i), d, FileIO.result));
//System.out.println("Decryption:"+"\n"+bob.decrypt(decryption.get(i),d,user.result));
}
text.setText(text.getText() + "" + decrypted);
filePswd.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
void displayAuthor(ActionEvent event) {
authorMark.setText("Copyright by" + "\n" + "Tomasz Kulnianin");
}
}