-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSource.cpp
More file actions
1058 lines (788 loc) · 25.1 KB
/
Source.cpp
File metadata and controls
1058 lines (788 loc) · 25.1 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
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <windows.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include "sha256.h"
#include "md5.h"
#include <CkPrng.h>
#include "uint256_t.h"
#include <stdlib.h>
#include <iomanip>
using namespace std;
SHA256 sha256;
void printVector(vector<bool> vec) {
int i = 0;
for (auto it = vec.begin(); it != vec.end(); it++) {
std::cout << *it << " ";
}
}
long long hash1(string s, int size) {
int hash, sum = 0;
int number = 10;
for (int i = 0; i < s.length(); i++) {
sum += (int)s[i] * number;
number *= pow(number, i);
number++;
}
long long pos = abs(sum % size);
return pos;
}
int hash2(string s, int size) {
int sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += pow(3, i) * (int)s[i];
}
int pos = abs(sum % size);
return pos;
}
long long hash3(string s, int size) {
int sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += (int)s[i] * pow(2, i) * pow(3, 2);
}
long long pos = abs(sum % size);
return pos;
}
long long hash4(string s, int size) {
int sum = 7;
for (int i = 0; i < s.length(); i++) {
sum += ((sum * 20) + ((int)s[i])) % size;
}
long long pos = abs(sum % size);
return pos;
}
long long hash5(string s, int size) {
int sum = 2;
int p = 3;
for (int i = 0; i < s.length(); i++) {
int ch = sum * 2;
sum += ch + (s[i] * pow(p, 2));
p++;
}
long long pos = abs(sum % size);
return pos;
}
long long hash6(string s, int size) {
long sum = 0, mul = 1;
for (int i = 0; i < s.length(); i++) {
mul = (i % 4 == 0) ? 1 : mul * 256;
sum += (int)s[i] * mul;
}
long long pos = abs(sum % size);
return pos;
}
long long hash7(string s, int size) {
int sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += (int)s[i];
}
sum = sum * sum * sum;
long pos = abs(sum % size);
return pos;
}
long long hash8(string s, int size) {
long long sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += (int)s[i] + ((long long)s[i] * i * pow(i, 3));
}
long long pos = abs(sum % size);
return pos;
}
long long hash9(string s, int size) {
long long sumeven = 0;
long long sumodd = 0;
long long sum = 0;
int number = 2;
for (int i = 0; i < s.length(); i++)
if (i % 2 == 0)
{
sumeven += number * (long long)s[i];
number *= 4;
}
else
{
sumodd += number * (long long)s[i];
number *= 5;
}
sum = sumeven + sumodd;
long long pos = abs(sum % size);
return pos;
}
int hash10(string s, int size) {
int sum = 0;
int fact = 1;
int number = 7;
for (int i = 0; i < s.length(); i++) {
sum += (int)s[i] * number * (number + 1);
number++;
}
int pos = abs(sum % size);
return pos;
}
long long hash11(string s, int size) {
int sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += (sum * 30) + int(s[i]);
}
long long pos = abs(sum % size);
return pos;
}
long long hash12(string s, int size) {
long long sum = 0;
int num = 2;
for (int i = 0; i < s.length(); i++) {
sum += ((sum * 30) / 2) + int(s[i]);
}
long long pos = abs(sum % size);
return pos;
}
long long hash13(string s, int size) {
long long sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += pow((15) + long long(s[i]), 2);
}
long long pos = (sum % size);
return pos;
}
long long hash14(string s, int size) {
long long sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += pow(s[i] * (i + 1), 2);
}
long long pos = (sum % size);
return pos;
}
long long hash15(string s, int size) {
long long sum = 0;
for (int i = 0; i < s.length(); i++) {
sum += long long(s[i]) * pow(long long(s[i]), 3);
}
long long pos = (sum % size);
return pos;
}
//-------------------------------------------------------------------------------------------------
//Generates a 32 byte salt value using an external library
string saltGenerator() {
CkPrng prng;
const char* saltHex = prng.genRandom(32, "hex");
return saltHex;
}
//-------------------------------------------------------------------------------------------------
//Checks the password through each hash
int userCheck(string password, vector<bool> v1, int size) {
int pos = hash1(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash2(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash3(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash4(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash5(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash6(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash7(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash8(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash9(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash10(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash11(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash12(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash13(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash14(password, size);
if (v1[pos] == 0) {
return 1;
}
pos = hash15(password, size);
if (v1[pos] == 0) {
return 1;
}
return 0;
}
//-------------------------------------------------------------------------------------------------
//Adding all the salt values from the file to the vector
void fillSaltVector(vector <string>& saltCheck) {
fstream inFile;
inFile.open("pwdFile.txt", ios::in | ios::out);
int count = 0;
string a, b, c;
while (inFile >> a >> b >> c) {
saltCheck.push_back(c);
}
}
//-------------------------------------------------------------------------------------------------
//Adding the user to the file
void addUserToFile(string uid, string hashedPwd, string salt) {
ofstream reg;
reg.open("pwdFile.txt", fstream::app);
reg << uid << " " << hashedPwd << " " << salt << "\n";
reg.close();
}
//-------------------------------------------------------------------------------------------------
//This function reads through the whole file to find the username entered by user for updating the password
int readFile(string uid, string& updateIdHash, string& updateIdSalt) {
fstream old;
old.open("pwdFile.txt", ios::in | ios::out);
string a1, b1, c1;
int flag = 0;
while (old >> a1 >> b1 >> c1)
{
if (uid.compare(a1) == 0) {
cout << "\nUser found!\n";
updateIdHash = b1;
updateIdSalt = c1;
flag = 1;
break;
}
}
if (flag == 1)
return 1;
else
return 0;
}
//-------------------------------------------------------------------------------------------------
//This function is to ensure that the salt value doesnt repeat although, this is highly very unlikely
int readSaltString(string salt) {
fstream old;
old.open("pwdFile.txt", ios::in | ios::out);
string a1, b1, c1;
int flag = 1;
while (old >> a1 >> b1 >> c1)
{
if (salt == c1) {
flag = 0;
break;
}
}
if (flag == 0)
return 0;
else
return 1;
}
//-------------------------------------------------------------------------------------------------
//Checking if the username already exists in the password file
int findUserName(string username) {
fstream old;
old.open("pwdFile.txt", ios::in | ios::out);
string a1, b1, c1;
int flag = 1;
while (old >> a1 >> b1 >> c1)
{
if (username == a1) {
flag = 0;
break;
}
}
if (flag == 0)
return 0;
else
return 1;
}
//-------------------------------------------------------------------------------------------------
//converting from hex to decimal, because the value is 256 bits, uint256_t an external library is used.
uint256_t converter(string password) {
int len = password.length();
uint256_t base = 1;
uint256_t decimalNum = 0;
for (int i = len - 1; i >= 0; i--) {
if (password[i] >= 48 && password[i] <= 57) {
decimalNum += (password[i] - 48) * base;
base = base * 16;
}
else if (password[i] >= 65 && password[i] <= 70) {
decimalNum += (int(password[i]) - 55) * base;
base = base * 16;
}
else if (password[i] >= 97 && password[i] <= 102) {
decimalNum += (int(password[i]) - 87) * base;
base = base * 16;
}
}
return decimalNum;
}
//-------------------------------------------------------------------------------------------------
//This function uses SHA256 and MD5 as cryptographic hash functions and hashes the bigrams using these
void func(string password1, vector<int>& vec) {
SHA256 sha256;
MD5 md5;
string password_sha256 = sha256(password1);
uint256_t decValueSHA256 = converter(password_sha256);
string password_md5 = md5(password1);
uint256_t decValueMD5 = converter(password_md5);
for (int j = 0; j < 15; j++) {
uint256_t sum = decValueMD5 + (j * decValueSHA256);
uint256_t pos = sum % 1000;
vec[pos] = 1;
sum = 0;
}
}
//-------------------------------------------------------------------------------------------------
//This is when a new user is created it is added to the userBloomFilter.txt file for password updates
void firstTimeReg(string uid) {
vector<int> vec(1000);
for (int i = 0; i < 1000; i++)
vec.at(i) = 0;
ofstream reg;
string str = "";
reg.open("usersBloomFilter.txt", fstream::app);
reg << uid << " ";
for (int i = 0; i < vec.size(); ++i) {
reg << vec[i];
}
reg << "\n";
reg.close();
}
//-------------------------------------------------------------------------------------------------
//This function updates the bloom filter 2 each time the password is updated
void updatingBloomFilter(string uid, vector<int> vec) {
fstream search;
search.open("usersBloomFilter.txt", fstream::in | fstream::out);
string uidFile, hugeNumber;
int fileVec;
int counter = 0;
vector<int> v1;
while (search >> uidFile >> hugeNumber) {
if (uidFile == uid) {
for (int i = 0; i < hugeNumber.length(); i++) {
const char* c = hugeNumber.c_str();
int temp = c[i] - 48;
v1.push_back(temp);
}
for (int i = 0; i < vec.size(); i++) {
if (vec.at(i) == 1) {
if (v1.at(i) == 0)
v1.at(i) = 1;
}
}
counter = v1.size();
}
}
search.close();
ofstream newwrite;
fstream s1;
newwrite.open("rep.txt", ios::in | ios::out);
s1.open("usersBloomFilter.txt", ios::in | ios::out);
while (s1 >> uidFile >> hugeNumber) {
if (uidFile == uid)
{
newwrite << uidFile;
newwrite << " ";
for (int i = 0; i < v1.size(); i++) {
newwrite << v1[i];
}
newwrite << "\n";
continue;
}
newwrite << uidFile << " " << hugeNumber << "\n";
}
newwrite.close();
s1.close();
newwrite.open("usersBloomFilter.txt", ios::trunc);
newwrite.close();
newwrite.open("usersBloomFilter.txt");
s1.open("rep.txt", ios::in | ios::out);
while (s1 >> uidFile >> hugeNumber) {
newwrite << uidFile << " " << hugeNumber << "\n";
}
newwrite.close();
s1.close();
}
//-------------------------------------------------------------------------------------------------
//This is the bloom filter 1, that reads the rockyou file and creates a vector changing the bits to 1 after hashing the passwords
void BloomFilter1(vector<bool>& f1, int size) {
fstream file;
file.open("rockyou-12.txt", ios::in | ios::out);
int pos = 0;
string s;
long long pos1 = 0;
while (getline(file, s)) {
pos = hash1(s, size);
f1[pos] = 1;
pos = hash2(s, size);
f1[pos] = 1;
pos1 = hash3(s, size);
f1[pos1] = 1;
pos1 = hash4(s, size);
f1[pos1] = 1;
pos1 = hash5(s, size);
f1[pos1] = 1;
pos = hash6(s, size);
f1[pos] = 1;
pos1 = hash7(s, size);
f1[pos1] = 1;
pos1 = hash8(s, size);
f1[pos1] = 1;
pos1 = hash9(s, size);
f1[pos1] = 1;
pos1 = hash10(s, size);
f1[pos1] = 1;
pos1 = hash11(s, size);
f1[pos1] = 1;
pos1 = hash12(s, size);
f1[pos1] = 1;
pos1 = hash13(s, size);
f1[pos1] = 1;
pos1 = hash14(s, size);
f1[pos1] = 1;
pos1 = hash15(s, size);
f1[pos1] = 1;
}
}
//-------------------------------------------------------------------------------------------------
//This is bloom filter 2 that divides the user entered password into bigrams
void BloomFilter2(string oldPwd, vector<int>& bf) {
int len = oldPwd.length();
string char1 = "_";
int size4 = 1000;
string s1, s2;
int noOfBigrams = 0;
vector<vector<int>> vec;
//For loop to traverse the password length and create bigrams
for (int i = 0; i < oldPwd.length(); i++) {
if (i == 0) {
//creating the first bigram with char '_'
string b1 = char1 + oldPwd[i];
vector<int> v1(size4);
for (int i = 0; i < v1.size(); i++) {
v1.at(i) = 0;
}
noOfBigrams++;
func(b1, v1);
vec.push_back(v1);
}
if (i > 0 && i < len) {
//creating bigrams using previos positions
s1 = oldPwd[i - 1];
s2 = oldPwd[i];
string s = s1 + s2;
vector <int> v2(size4);
for (int i = 0; i < v2.size(); i++) {
v2.at(i) = 0;
}
noOfBigrams++;
func(s, v2);
vec.push_back(v2);
}
if (i == (len - 1)) {
//creating the last bigram with char '_'
string b1 = (oldPwd[len - 1] + char1);
vector<int> v3(size4);
for (int i = 0; i < v3.size(); i++)
{
v3.at(i) = 0;
}
noOfBigrams++;
func(b1, v3);
vec.push_back(v3);
}
}
for (int i = 0; i < noOfBigrams; i++) {
for (int j = 0; j < vec[i].size(); j++) {
if (vec[i][j] == 1) {
bf[j] = 1;
}
}
cout << endl;
}
}
//-------------------------------------------------------------------------------------------------
//This function creates a new user in the password file, with their UserID, hashed password and salt
void registerUser(vector<bool>f1, int size) {
vector <string> saltCheck;
std::string uid, pwd, pwdConfirm;
fstream check;
fstream fileopen;
int count = 0;
string a, b, c;
int val = 0;
string saltedPwd = "";
string hashedPwd = "";
string salt = "";
fstream file1;
string a1, b1, c1;
int flag = 0;
check.open("pwdFile.txt", ios::in | ios::out);
fileopen.open("usersBloomFilter.txt", ios::in | ios::out);
cout << "\nEnter a username:\n";
cin >> uid;
while (uid.length() < 6) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "Username too short! Username length must be atleast 6 characters\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
cout << "Enter a new username:\n";
cin >> uid;
}
//This part of code checks if a username already exists in the password file
int value = 0;
while (value == 0) {
value = findUserName(uid);
if (value == 0) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "\nUsername taken! Enter another username:\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
cin >> uid;
}
}
cout << "\nEnter a password:\n";
cin >> pwd;
//Checking if user entered password exists in the common password file
val = userCheck(pwd, f1, size);
//This part of code checks if the password is in the common password file using the function userCheck
while (true) {
if (val == 0) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "\nToo common. Please enter a strong password:\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
cin >> pwd;
val = userCheck(pwd, f1, size);
continue;
}
else
break;
}
cout << "\nConfirm Password:\n";
cin >> pwdConfirm;
while (pwdConfirm != pwd) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "Password does not match. Enter again:\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
cin >> pwdConfirm;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
cout << "\nPassword Accepted!\n\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
cout << "\nUser Registered!\n";
check.close();
firstTimeReg(uid);
file1.open("PwdFile.txt", ios::in | ios::out);
while (flag == 0) {
salt = saltGenerator();
flag = readSaltString(salt);
}
saltedPwd = pwdConfirm + salt;
hashedPwd = sha256(saltedPwd);
//Adding users to Password File
addUserToFile(uid, hashedPwd, salt);
//Loading the salt vector with all the salt values from password file
fillSaltVector(saltCheck);
vector <int> bf2(1000);
BloomFilter2(pwdConfirm, bf2);
updatingBloomFilter(uid, bf2);
}
//-------------------------------------------------------------------------------------------------
//This function calculates the jaccard coefficient, using the two bloom filter's true values
double jaccardCoeff(vector<int> B2, string uid) {
vector<bool> B1;
fstream jack;
jack.open("usersBloomFilter.txt", fstream::in | fstream::out);
string uidFile, hugeNumber;
while (jack >> uidFile >> hugeNumber) {
if (uidFile == uid)
{
for (int i = 0; i < hugeNumber.length(); i++)
{
const char* c = hugeNumber.c_str();
int temp = c[i] - 48;
B1.push_back(temp);
}
}
}
//Calculating truth values of old passwords from the bloom filter 2
int KB1 = 0;
for (int i = 0; i < B1.size(); i++) {
if (B1.at(i) == 1) {
KB1++;
}
}
//Calculating truth values from bloom filter 2, of the new password
int KB2 = 0;
for (int i = 0; i < B2.size(); i++) {
if (B2.at(i) == 1) {
KB2++;
}
}
//Calculating common number of true values in both sets (old passwords and new password)
int YB1B2 = 0;
for (int i = 0; i < B1.size(); i++) {
if (B1.at(i) == 1 && B2.at(i) == 1) {
YB1B2++;
}
}
double jaccardCoefficient = 0;
double denominator = (double)(KB1 + KB2) - YB1B2;
jaccardCoefficient = (double)YB1B2 / denominator;
return jaccardCoefficient;
}
//-------------------------------------------------------------------------------------------------
//This function updates the password file with the user's latest updated password
void updatePwdFile(string updateId, string newPwd) {
SHA256 sha256;
fstream file;
fstream file1;
string username, hashedPwd, salt;
string newHash = "";
string final1 = "";
file.open("PwdFile.txt", ios::in | ios::out);
//A new temporary file is created into which the updated password is enetred
file1.open("copy.txt", ios::in | ios::out);
while (file >> username >> hashedPwd >> salt) {
if (username == updateId) {
newHash = newPwd + salt;
final1 = sha256(newHash);
file1 << username << " " << final1 << " " << salt << "\n";
continue;
}
file1 << username << " " << hashedPwd << " " << salt << "\n";
}
file.close();
file1.close();
file.open("PwdFile.txt", ios::trunc);
file.close();
file.open("PwdFile.txt", ios::in | ios::out);
file1.open("copy.txt", ios::in | ios::out);
//From the copy.txt file, the required user's password is selected and updated in the password file
while (file1 >> username >> hashedPwd >> salt) {
file << username << " " << hashedPwd << " " << salt << "\n";
}
remove("copy.txt");
}
//-------------------------------------------------------------------------------------------------
//This prompts user to enter a new password during updating process, checks through the hashes along with the jaccard coefficient.
//If the jaccard coefficient gives a value greater than threshold, this function is called again for entering a new password
string enterNewPwd(vector<bool>f1, int size, int counters) {
string password1;
cout << "Enter new password:\n";
cin >> password1;
//Checking if user entered password exists in the common password file
int val1 = 0;
val1 = userCheck(password1, f1, size);
while (true) {
if (val1 == 0) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "\nToo common. Please enter a strong password:\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
cin >> password1;
val1 = userCheck(password1, f1, size);
continue;
}
else
break;
}
return password1;
}
//-------------------------------------------------------------------------------------------------
int main() {
srand(time(NULL));
int size = 44035;
vector<bool> f1(size);
string s;
fstream file;
int answer;
for (int i = 0; i < f1.size(); i++) {
f1.at(i) = 0;
}
BloomFilter1(f1, size);
cout << "*******************************\n\n";
cout << "Choose your option below:\n\n";
cout << "1. New User\n\n";
cout << "2. Update existing password\n\n";
cout << "Your input: ";
cin >> answer;
cout << "\n*******************************\n\n";
switch (answer) {
case 1:
registerUser(f1, size);
break;
case 2:
string oldPwd;
string updateId;
string updateIdSalt;
string updateIdHash;
string newPwd;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "Password Expired! Please update NOW!\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
int flag3 = 0;
//This while loop will keep asking the user for their username if not found in the existing user file
while (flag3 == 0) {
cout << "Enter username: ";
cin >> updateId;