This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuresetstudentpassword.pas
418 lines (383 loc) · 10.2 KB
/
uresetstudentpassword.pas
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
unit UResetStudentPassword;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, HTTPSend, ssl_openssl, fpjson, jsonparser;
type
{ TRSPForm }
TRSPForm = class(TForm)
cancelButton: TButton;
capitalLetters: TCheckBox;
cbLabel1: TLabel;
cbLabel2: TLabel;
cbLabel3: TLabel;
cbLabel4: TLabel;
confirmButton: TButton;
separatorOne: TShape;
separatorTwo: TShape;
stepThreeLabel: TLabel;
stepTwoLabel: TLabel;
stepOneLabel: TLabel;
search: TEdit;
lehrerLabel3: TLabel;
usernames: TListBox;
teacherPw: TEdit;
teacherUname: TEdit;
eightChars: TCheckBox;
lehrerLabel2: TLabel;
lehrerLabel1: TLabel;
infoLabel1: TLabel;
infoLabel2: TLabel;
newpw: TEdit;
newpw2: TEdit;
newPwLabel: TLabel;
newPwTwoLabel: TLabel;
numbers: TCheckBox;
sameLabel: TLabel;
smallLetters: TCheckBox;
username: TEdit;
usernameLabel: TLabel;
procedure cancelButtonClick(Sender: TObject);
procedure capitalLettersChange(Sender: TObject);
procedure confirmButtonClick(Sender: TObject);
procedure eightCharsChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure infoLabel3Click(Sender: TObject);
procedure newpw2Change(Sender: TObject);
procedure newpwChange(Sender: TObject);
procedure numbersChange(Sender: TObject);
procedure searchChange(Sender: TObject);
procedure smallLettersChange(Sender: TObject);
procedure teacherPwChange(Sender: TObject);
procedure usernamesSelectionChange(Sender: TObject; User: boolean);
private
pwsame, eight, small, capital, number, pwfirst, pwteacher: boolean;
procedure controlConfirmButton;
procedure loadUsers;
procedure reset;
function sendRequest(url, params: string): string;
function MemStreamToString(Strm: TMemoryStream): AnsiString;
public
{ public declarations }
end;
var
RSPForm: TRSPForm;
RSPuserdata, RSPfullUserdata, RSPsearchUserdata: TStrings;
implementation
uses
PCS;
{$R *.lfm}
{ TRSPForm }
procedure TRSPForm.newpwChange(Sender: TObject);
var
i: integer;
cache: string;
begin
capital:=newpw.text <> lowercase(newpw.text);
small:=newpw.text <> uppercase(newpw.text);
if (length(newpw.text) >= 8) then begin
eight:=true;
end
else begin
eight:=false;
end;
i:=0;
number:=false;
cache:=newpw.text;
for i:=1 to length(cache) do begin
if (cache[i] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']) then begin
number:=true;
end;
end;
if (capital) then begin
capitalLetters.checked:=true;
cbLabel2.font.color:=clDefault;
end
else begin
capitalLetters.checked:=false;
cbLabel2.font.color:=clRed;
end;
if (small) then begin
smallLetters.checked:=true;
cbLabel1.font.color:=clDefault;
end
else begin
smallLetters.checked:=false;
cbLabel1.font.color:=clRed;
end;
if (eight) then begin
eightChars.checked:=true;
cbLabel3.font.color:=clDefault;
end
else begin
eightChars.checked:=false;
cbLabel3.font.color:=clRed;
end;
if (number) then begin
numbers.checked:=true;
cbLabel4.font.color:=clDefault;
end
else begin
numbers.checked:=false;
cbLabel4.font.color:=clRed;
end;
if (capital) and (small) and (eight) and (number) then begin
pwfirst:=true;
end
else begin
pwfirst:=false;
end;
newpw2change(nil);
controlConfirmButton;
end;
procedure TRSPForm.reset;
begin
search.text:='';
teacherUname.text:='';
teacherPw.text:='';
newpw.text:='';
newpw2.text:='';
username.text:='';
newpw2change(nil);
controlConfirmButton;
sameLabel.visible:=false;
search.setFocus;
end;
procedure TRSPForm.teacherPwChange(Sender: TObject);
begin
if (length(teacherPw.text) > 0) then begin
pwteacher:=true;
end
else begin
pwteacher:=false;
end;
controlConfirmButton;
end;
procedure TRSPForm.newpw2Change(Sender: TObject);
begin
sameLabel.visible:=true;
if (newpw.text = newpw2.text) and (newpw.text <> '') then begin
sameLabel.font.color:=clGreen;
sameLabel.caption:='Passwörter stimmen überein.';
pwsame:=true;
end
else if (newpw.text = '') then begin
sameLabel.font.color:=clRed;
sameLabel.caption:='Achtung: Passwort zu kurz!';
pwsame:=false;
end
else begin
sameLabel.font.color:=clRed;
sameLabel.caption:='Achtung: Passwörter stimmen nicht überein!';
pwsame:=false;
end;
controlConfirmButton;
end;
procedure TRSPForm.FormCreate(Sender: TObject);
begin
pwsame:=false;
eight:=false;
small:=false;
capital:=false;
number:=false;
pwfirst:=false;
pwteacher:=false;
controlConfirmButton;
end;
procedure TRSPForm.FormHide(Sender: TObject);
begin
reset;
end;
procedure TRSPForm.cancelButtonClick(Sender: TObject);
begin
close;
end;
procedure TRSPForm.confirmButtonClick(Sender: TObject);
var
response: string;
begin
response:=sendRequest('https://'+serverURL+'/client.php', 'usage=pwreset&globalpw='+globalPW+'&machine='+mac+'&ip='+ip+'&uname='+username.text+'&newpw='+newpw.text+'&newpw2='+newpw2.text+'&teacheruser='+teacherUname.text+'&teacherpw='+teacherPw.text);
if (response = 'success') then begin
showMessage('Passwort erfolgreich geändert.');
reset;
close;
end
else if (response = 'noteacher') or (response = 'wrongteacher') then begin
showMessage('Lehrer-Benutzername und / oder Passwort falsch. Bitte erneut versuchen.');
teacherPw.text:='';
end
else if (response = 'nouser') then begin
showMessage('Benutzername falsch. Bitte erneut versuchen.');
newpw.text:='';
newpw2.text:='';
end
else if (response = 'notsame') then begin
showMessage('Die eingegebenen Passwörter stimmen nicht überein. Bitte erneut versuchen.');
newpw.text:='';
newpw2.text:='';
end
else if (response = 'notallowed') then begin
showMessage('Es ist nicht möglich, ein Lehrerpasswort zurückzusetzen.');
newpw.text:='';
newpw2.text:='';
end
else begin
showMessage('Es ist ein Fehler aufgetreten.');
end;
end;
procedure TRSPForm.smallLettersChange(Sender: TObject);
begin
if (small) then begin
smallLetters.checked:=true;
end
else begin
smallLetters.checked:=false;
end;
end;
procedure TRSPForm.capitalLettersChange(Sender: TObject);
begin
if (capital) then begin
capitalLetters.checked:=true;
end
else begin
capitalLetters.checked:=false;
end;
end;
procedure TRSPForm.eightCharsChange(Sender: TObject);
begin
if (eight) then begin
eightChars.checked:=true;
end
else begin
eightChars.checked:=false;
end;
end;
procedure TRSPForm.numbersChange(Sender: TObject);
begin
if (number) then begin
numbers.checked:=true;
end
else begin
numbers.checked:=false;
end;
end;
procedure TRSPForm.controlConfirmButton;
begin
if (pwfirst) and (pwsame) and (pwteacher) then begin
confirmButton.enabled:=true;
end
else begin
confirmButton.enabled:=false;
end;
end;
procedure TRSPForm.loadUsers;
var
response: string;
c: integer;
jData: TJSONData;
begin
response:=sendRequest('https://'+serverURL+'/client.php', 'usage=userlist&globalpw='+globalPW+'&machine='+mac+'&ip='+ip+'&sort=students');
if (response = '') then begin
if (allowOffline) then begin
halt;
end
else begin
showMessage('Netzwerkfehler. Programm wird beendet.');
halt;
end;
end
else if (response = '!') then begin
showMessage('Konfigurationsfehler. Programm wird beendet.');
halt;
end
else begin
RSPuserdata:=TStringList.create;
RSPfullUserdata:=TStringList.create;
RSPsearchUserdata:=TStringList.create;
usernames.items.clear();
jData:=GetJSON(response);
c:=0;
while (c < jData.count) do begin
RSPuserdata.add(jData.FindPath(IntToStr(c)+'[2]').AsString);
RSPsearchUserdata.add(jData.FindPath(IntToStr(c)+'[2]').AsString);
RSPfullUserdata.add(jData.FindPath(IntToStr(c)+'[0]').AsString+' '+jData.FindPath(IntToStr(c)+'[1]').AsString+' ('+jData.FindPath(IntToStr(c)+'[2]').AsString+')');
usernames.items.add(jData.FindPath(IntToStr(c)+'[0]').AsString+' '+jData.FindPath(IntToStr(c)+'[1]').AsString+' ('+jData.FindPath(IntToStr(c)+'[2]').AsString+')');
c:=c+1;
end;
end;
end;
procedure TRSPForm.usernamesSelectionChange(Sender: TObject; User: boolean);
var
counter: integer;
begin
counter:=0;
while (counter < RSPsearchUserdata.count) do begin
if counter = (usernames.ItemIndex) then begin
username.text:=RSPsearchUserdata[counter];
break;
end;
counter:=counter+1;
end;
newpw.setFocus;
end;
procedure TRSPForm.searchChange(Sender: TObject);
var
counter: NativeInt;
rpl: string;
begin
usernames.items.clear();
RSPsearchUserdata.clear();
counter:=0;
while (counter < RSPuserdata.count) do begin
rpl:=StringReplace(LowerCase(RSPfullUserdata[counter]), LowerCase(search.text), '', [rfReplaceAll]);
if not(LowerCase(RSPfullUserdata[counter]) = rpl) or (search.Text = '') then begin
usernames.items.add(RSPfullUserdata[counter]);
RSPsearchUserdata.add(RSPuserdata[counter]);
end;
counter:=counter+1;
end;
end;
procedure TRSPForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
begin
if (key = 13) then begin
if (RSPForm.activeControl = search) then begin
if (RSPsearchUserdata.count = 1) then begin
username.text:=RSPsearchUserdata[0];
newpw.setFocus;
end;
end;
end;
end;
procedure TRSPForm.FormShow(Sender: TObject);
begin
search.setFocus;
loadUsers;
end;
procedure TRSPForm.infoLabel3Click(Sender: TObject);
begin
end;
function TRSPForm.sendRequest(url, params: string): string;
var
Response: TMemoryStream;
begin
Response := TMemoryStream.Create;
try
if HttpPostURL(url, params, Response) then
result:=MemStreamToString(Response);
finally
Response.Free;
end;
end;
function TRSPForm.MemStreamToString(Strm: TMemoryStream): AnsiString;
begin
if Strm <> nil then begin
Strm.Position := 0;
SetString(Result, PChar(Strm.Memory), Strm.Size);
end;
end;
end.