-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrecover-account.js
More file actions
65 lines (54 loc) · 1.55 KB
/
recover-account.js
File metadata and controls
65 lines (54 loc) · 1.55 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
const fb = require("firebase-admin");
const serviceAccount = require("../private/service-account.json");
// This script will reset passwords. Used when students are unable to receive emails.
const accountsToRecover = [
"xxxxxxxxxxxx"
];
const passwordLength = 10;
const passwordCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
//////////////////////////////////////
const makePassword = () => {
var result = "";
var charactersLength = passwordCharacters.length;
for (var i = 0; i < passwordLength; i++) {
result += passwordCharacters.charAt(
Math.floor(Math.random() * charactersLength)
);
}
return result;
};
fb.initializeApp({
credential: fb.credential.cert(serviceAccount),
databaseURL: "https://parallel-beta-31dc4.firebaseio.com",
});
const updateUserPassword = (email) =>
fb
.auth()
.getUserByEmail(email)
.then(async (user) => {
const password = makePassword();
await fb.auth().updateUser(user.uid, {
password,
});
console.log(`Given user "${user.email}" password ${password}`);
})
.catch((err) => {
err.message = `${err.message} - ${email}`;
throw err;
});
const run = async () => {
console.log("\n\n");
for (const email of accountsToRecover) {
await updateUserPassword(email);
}
};
run()
.then(() => {
console.error("\n\n\nSuccess recovering accounts");
process.exit(0);
})
.catch((err) => {
console.error("\n\n\nError recovering accounts!");
console.error(err.message + "\n");
process.exit(1);
});