Advertisement
zvoulgaris

Basic Password Generator

Feb 4th, 2020
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. LCC = "qwertyuiopasdfghjklzxcvbnm"
  2. UCC = uppercase(LCC)
  3. NC = "1234567890"
  4.  
  5. function gp(L::Int64 = 10, ULC::Bool = true, UUC::Bool = true, UNC::Bool = true)
  6. if !(ULC||UUC||UNC); println("At least one of the requirements needs to be true!"); return ""; end
  7. if L <= 8; println("Passwords of this size can be easily cracked! Please pick a larger number of characters."); return ""; end
  8. PC = ""
  9. if ULC; PC = string(PC, LCC); end
  10. if UUC; PC = string(PC, UCC); end
  11. if UNC; PC = string(PC, NC); end
  12. n = length(PC)
  13. OK = false
  14. pw = [' ']
  15.  
  16. while !OK
  17. pw = Array{Char}(undef, L)
  18. OK_LCC = OK_UCC = OK_NC = false
  19.  
  20. for i = 1:L
  21. r = rand(1:n)
  22. pw[i] = PC[r]
  23.  
  24. if ULC
  25. if PC[r] in LCC; OK_LCC = true; end
  26. else
  27. OK_LCC = true
  28. end
  29.  
  30. if UUC
  31. if PC[r] in UCC; OK_UCC = true; end
  32. else
  33. OK_UCC = true
  34. end
  35.  
  36. if UNC
  37. if PC[r] in NC; OK_NC = true; end
  38. else
  39. OK_NC = true
  40. end
  41. end
  42.  
  43. OK = OK_LCC && OK_UCC && OK_NC
  44. end
  45.  
  46. return join(pw,"")
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement