-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordGenerator.fs
More file actions
66 lines (53 loc) · 2.19 KB
/
Copy pathPasswordGenerator.fs
File metadata and controls
66 lines (53 loc) · 2.19 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
namespace PasswordManager
module generador =
open PasswordManager.Types
open System
type char_set =
| UPPER = 0
| LOWER = 1
| NUM = 2
| LOG = 3
| MATH = 4
| SLASHES = 5
let lowers = [ for c in 'a' .. 'z' -> c ]
let uppers = [ for c in 'A' .. 'Z' -> c]
let numbers = [for i in 0..9 -> i]
let logograms = ["#";"$";"&";"%";"@";"^";"~"]
let math_symbols = ["<";">";"*";"+";"!";"?";"="]
let bars = ["\\";"/";"_";"-"]
let gen ( op: Password_Form ) =
(**
let mutable checks = {
size = op.size;
show = op.show;
upper_case = op.upper_case;
lower_case = op.lower_case;
numbers = op.numbers;
slashes = op.slashes;
math_symbols = op.math_symbols;
logograms = op.logograms
}
**)
let rdn = Random()
let mutable allowed = [| |]
if op.upper_case then allowed <- Array.append allowed [| char_set.UPPER |]
if op.lower_case then allowed <- Array.append allowed [| char_set.LOWER |]
if op.numbers then allowed <- Array.append allowed [| char_set.NUM |]
if op.slashes then allowed <- Array.append allowed [| char_set.SLASHES |]
if op.math_symbols then allowed <- Array.append allowed [| char_set.MATH |]
if op.logograms then allowed <- Array.append allowed [| char_set.LOG |]
if allowed.Length <= 1 || op.size < 2 then None
else
let mutable password = ""
for i in 0.. op.size - 1 do
let dk = allowed[rdn.Next allowed.Length]
let char_s =
match dk with
| char_set.UPPER -> string(uppers[rdn.Next uppers.Length])
| char_set.LOWER -> string(lowers[rdn.Next lowers.Length])
| char_set.NUM -> string(numbers[rdn.Next numbers.Length])
| char_set.LOG -> logograms[rdn.Next logograms.Length]
| char_set.MATH -> math_symbols[rdn.Next math_symbols.Length]
| char_set.SLASHES -> bars[rdn.Next bars.Length]
password <- String.Concat (password, char_s)
Some password