Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LCC = "qwertyuiopasdfghjklzxcvbnm"
- UCC = uppercase(LCC)
- NC = "1234567890"
- function gp(L::Int64 = 10, ULC::Bool = true, UUC::Bool = true, UNC::Bool = true)
- if !(ULC||UUC||UNC); println("At least one of the requirements needs to be true!"); return ""; end
- if L <= 8; println("Passwords of this size can be easily cracked! Please pick a larger number of characters."); return ""; end
- PC = ""
- if ULC; PC = string(PC, LCC); end
- if UUC; PC = string(PC, UCC); end
- if UNC; PC = string(PC, NC); end
- n = length(PC)
- OK = false
- pw = [' ']
- while !OK
- pw = Array{Char}(undef, L)
- OK_LCC = OK_UCC = OK_NC = false
- for i = 1:L
- r = rand(1:n)
- pw[i] = PC[r]
- if ULC
- if PC[r] in LCC; OK_LCC = true; end
- else
- OK_LCC = true
- end
- if UUC
- if PC[r] in UCC; OK_UCC = true; end
- else
- OK_UCC = true
- end
- if UNC
- if PC[r] in NC; OK_NC = true; end
- else
- OK_NC = true
- end
- end
- OK = OK_LCC && OK_UCC && OK_NC
- end
- return join(pw,"")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement