-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
239 lines (217 loc) · 5.81 KB
/
test.js
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
// CODE TO PUSH AN ACTIVITY DOCUMENT TO MONGODB (MAINTAINING PURPOSE)
// const Activity = mongoose.model("Activity", activitiesSchema);
// const activity1 = new Activity({
// Name: "Camping",
// ServiceProvider: "Goldenvoice",
// Description: "Multi day outdoor experience with a music festival",
// Rating: "5/5",
// Date: "04/09/2021",
// Time: "12:00 pm",
// Image: "https://s.abcnews.com/images/Entertainment/coachella-2017-02-gty-jc-18...",
// Venue: "Empire Polo Club",
// Longitude: "-121.879898",
// Latitude: "37.346792",
// Price: 100,
// Tags: ["camping", "outdoors", "nature", "physical"]
// });
//
// const defaultActivities = [activity1];
//
// Activity.insertMany(defaultItems, function(err){
// if (err) {
// console.log(err);
// } else {
// console.log("Successfully savevd default items to DB.");
// }
// });
// TEST USER SCHEMA AND HASHING
/**
* Generates random hex string of length 16 as salt
* @function
*/
var getSalt = function(){
return crypto.randomBytes(Math.ceil(8)).toString('hex').slice(0,16);
};
/**
* Hash sensitive information with ripemd160.
* @function
* @param {string} phase - Phase needed to be hashed.
* @param {string} salt - Data to be validated.
*/
var hash = function(phase, salt){
var hash = crypto.createHmac('ripemd160', salt); // Hashing algorithm ripemd160
hash.update(phase);
return hash.digest('hex');
};
const crypto = require('crypto');
const { result } = require('lodash');
const mongoose = require("mongoose");
mongoose.connect("mongodb+srv://pruthvi:[email protected]/myFirstDatabase?retryWrites=true", {useNewUrlParser: true, useUnifiedTopology: true});
const testusersSchema = {
FirstName: String,
LastName: String,
EmailID: String,
Salt: String,
Password: String,
Street: String,
City: String,
State: String,
ZipCode: String,
CredCardName: String,
CredCardNumb: String,
Last4Digits: String,
CVC: String,
ExpireDate: String,
Points: Number,
isLocked: Boolean
};
const Test = mongoose.model("Test", testusersSchema);
// test1
salt1 = getSalt()
pass1 = "test2"
number1 = "1234123456785678"
cvc1 = "123"
const testUser1 = new Test({
FirstName: "Pruthvi",
LastName: "Punwar",
EmailID: "[email protected]",
Salt: salt1,
Password: hash(pass1, salt1),
Street: "2327 Lskm",
City: "San Jose",
State: "CA",
ZipCode: "95138",
CredCardName: "Pruthvi Punwar",
CredCardNumb: hash(number1, salt1),
Last4Digits: "5678",
CVC: hash(cvc1, salt1),
Expiry: "01/23",
Points: 420,
isLocked: false
});
// test2
salt2 = getSalt()
pass2 = "cuccu123"
number2 = "1111111111111111"
cvc2 = "456"
const testUser2 = new Test({
FirstName: "Le Duy",
LastName: "Vu",
EmailID: "[email protected]",
Salt: salt2,
Password: hash(pass2, salt2),
Street: "1 Washington Square",
City: "San Jose",
State: "CA",
ZipCode: "95616",
CredCardName: "Le Duy Vu",
CredCardNumb: hash(number2, salt2),
Last4Digits: "1111",
CVC: hash(cvc2, salt2),
Expiry: "06/22",
Points: 69,
isLocked: false
});
// test3
salt3 = getSalt()
pass3 = "test"
number3 = "1234567887654321"
cvc3 = "999"
const testUser3 = new Test({
FirstName: "Peter",
LastName: "Parker",
EmailID: "[email protected]",
Salt: salt3,
Password: hash(pass3, salt3),
Street: "2328 mIink nm",
City: "San Jose",
State: "CA",
ZipCode: "91107",
CredCardName: "Peter Parker",
CredCardNumb: hash(number3, salt3),
Last4Digits: "4321",
CVC: hash(cvc3, salt3),
Expiry: "12/22",
Points: 0,
isLocked: false
});
// test4
salt4 = getSalt()
pass4 = "1234"
number4 = "9999999999999999"
cvc4 = "789"
const testUser4 = new Test({
FirstName: "Rishab",
LastName: "Pandit",
EmailID: "[email protected]",
Salt: salt4,
Password: hash(pass4, salt4),
Street: "2870 E Colorado Blvd",
City: "San Jose",
State: "CA",
ZipCode: "91123",
CredCardName: "Rishab Pandit",
CredCardNumb: hash(number4, salt4),
Last4Digits: "9999",
CVC: hash(cvc4, salt4),
Expiry: "08/25",
Points: 100,
isLocked: false
});
const testCases = [testUser5];
Test.insertMany(testCases, function(err){
if (err) {
console.log(err);
} else {
console.log("Successfully saved default items to DB.");
}
});
// Test cases
// var test1 = "123"
// console.log("Original: " + test1)
// var salt = getSalt()
// console.log("Salt used: " + salt)
// var res = hash(test1, salt)
// console.log("Hashed: " + res)
// if (hash(test1, salt) === res)
// console.log("True")
// console.log("Login: " + hash(test1, salt))
////////////////////////////////////////////////////////////////////////////////////////////////////
// ADDING SERVICE PROVIDER INTO DB
// for service provider
salt1 = getSalt()
pass1 = "pass"
const testServiceProvider1 = new ServiceProvider({
Name: "Tinder",
Email: "[email protected]",
Salt: salt1,
Password: hash(pass1, salt1),
isLocked: false
});
// for service provider
salt2 = getSalt()
pass2 = "pass"
const testServiceProvider2 = new ServiceProvider({
Name: "City of San Jose",
Email: "[email protected]",
Salt: salt2,
Password: hash(pass2, salt2),
isLocked: false
});
salt3 = getSalt()
pass3 = "pass"
const testServiceProvider3 = new ServiceProvider({
Name: "PhysX",
Email: "[email protected]",
Salt: salt3,
Password: hash(pass3, salt3),
isLocked: false
});
const testCases = [testServiceProvider1, testServiceProvider2, testServiceProvider3];
ServiceProvider.insertMany(testCases, function(err){
if (err) {
console.log(err);
} else {
console.log("Successfully saved default items to DB.");
}
});