Skip to content

Commit e20b79b

Browse files
MichaelDesantiskylecarbs
authored andcommitted
Generate secure passwords, fixes issue #26 (#51)
1 parent e99f8ab commit e20b79b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

packages/server/src/cli.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { field, logger } from "@coder/logger";
22
import { ServerMessage, SharedProcessActiveMessage } from "@coder/protocol/src/proto";
33
import { Command, flags } from "@oclif/command";
44
import { fork, ForkOptions, ChildProcess } from "child_process";
5+
import { randomFillSync } from "crypto";
56
import * as fs from "fs";
67
import * as os from "os";
78
import * as path from "path";
@@ -136,13 +137,9 @@ export class Entry extends Command {
136137
let password = flags["password"];
137138
if (!password) {
138139
// Generate a random password
139-
const passwordLength = 12;
140-
const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
141-
const chars = [];
142-
for (let i = 0; i < passwordLength; i++) {
143-
chars.push(possible[Math.floor(Math.random() * possible.length)]);
144-
}
145-
password = chars.join("");
140+
const buffer = Buffer.alloc(12);
141+
randomFillSync(buffer);
142+
password = buffer.toString("hex");
146143
}
147144

148145
const hasCustomHttps = certData && certKeyData;

0 commit comments

Comments
 (0)