Author Topic: (Challenge) Password Generator  (Read 8934 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(Challenge) Password Generator
« on: August 29, 2013, 11:15:56 AM »
Using the language of your choice, create a password generator with at least one argument. The argument could be number of characters for example.

We have one here for example.


Good luck and have fun! :)
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (Challenge) Password Generator
« Reply #1 on: August 29, 2013, 11:28:00 AM »
I've notice that many require passwords to be a minimum length, at least one number, one capital & one lower case letter and some require a "special character".
So I can't use my password 4321.  >:D
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

andrew_nao

  • Guest
Re: (Challenge) Password Generator
« Reply #2 on: August 29, 2013, 12:09:35 PM »
I've notice that many require passwords to be a minimum length, at least one number, one capital & one lower case letter and some require a "special character".
So I can't use my password 4321.  >:D

thats the kind of combo you see on luggage  :lmao:

Vaidas

  • Newt
  • Posts: 66
Re: (Challenge) Password Generator
« Reply #3 on: August 29, 2013, 12:42:34 PM »
U53 L337 $P34|< Ph0R p455\/\/0RD :)
(mapcar 'chr '(107 105 116 111 120 46 99 111 109))

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: (Challenge) Password Generator
« Reply #4 on: August 29, 2013, 01:48:56 PM »
Source code attached for a C++ CMake based project using a shared lib (dll).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: (Challenge) Password Generator
« Reply #5 on: August 29, 2013, 03:25:29 PM »
6 to 10 digits
Argument: 0, 1 or 2 for easy, medium or hard password (as in OP sample)
Code - Auto/Visual Lisp: [Select]
  1. (defun password (x / l n r)
  2.   (if
  3.     (vl-position x '(0 1 2))
  4.     (progn
  5.       (setq l (nth x '((48 49 50 51 52 53 54 55 56 57 97 98 99 100 101 102 103 104 105
  6.                         106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122)
  7.                        (48 49 50 51 52 53 54 55 56 57 65 66 67 68 69 70 71 72 73 74 75 76 77
  8.                         78 79 80 81 82 83 84 85 86 87 88 89 90 97 98 99 100 101 102 103 104
  9.                         105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122)
  10.                        (33 35 36 37 38 39 40 41 42 43 44 45 46 48 49 50 51 52 53 54 55 56
  11.                         57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  12.                         81 82 83 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 102 103
  13.                         104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126))
  14.               )
  15.             n (length l)
  16.             )
  17.       (repeat (+ 6 (rem (dos_random) 5))
  18.         (setq r (cons (nth (rem (dos_random) n) l) r))
  19.         )
  20.       (vl-list->string r)
  21.       )
  22.      (not (princ "\nInvalid argument.\n0 - easy\n1 - medium\n2 - hard\n"))
  23.     )
  24.   )

Vaidas

  • Newt
  • Posts: 66
Re: (Challenge) Password Generator
« Reply #6 on: August 29, 2013, 04:41:16 PM »
Code: [Select]
; n - number of chars
; d - divisor
(defun kx:pwd (n d / p r)
 (setq p "")
 (repeat n
  (setq p (strcat p (chr (setq r (+ 33 (fix (* 0.94 (atoi (substr (rtos (getvar "date") 2 8) 15)))))))))
  (vl-cmdf "_delay" (/ r d))
 )
 p
)

; example:
(repeat 8
 (terpri)
 (princ (kx:pwd 8 4))
)

; or with random divisor:
(defun rnd ()
 (1+ (atoi (substr (rtos (getvar "date") 2 8) 16)))
)

(repeat 8
 (terpri)
 (princ (kx:pwd 8 (rnd)))
)
« Last Edit: August 29, 2013, 05:04:54 PM by Vaidas »
(mapcar 'chr '(107 105 116 111 120 46 99 111 109))

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: (Challenge) Password Generator
« Reply #7 on: August 29, 2013, 06:11:21 PM »
This was a lot of fun Mark!! :D

I have been playing around with this challenge on and off. In the attached zip I have given the source and executable. What I have done since the above version was to start using the "Mersenne Twister" random number generator and also built a testing app. The testing app showed me that I needed to play with the "SEED" a little more (basically, wait for a bit then generate a new random number to get better/more random results). So I also started to use a higher precision timer class to give me a better/faster SEED calculator.

-e.g.
Code - C++: [Select]
  1. ...
  2. while(seed == oldSeed) {
  3.     t2 = pctimer();
  4.     seed = t1+t2;
  5. }

The attached version generates a new random number for every character in the string now (waits a long time). :)

Anyways, fun challenge.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) Password Generator
« Reply #8 on: August 29, 2013, 06:40:54 PM »
Hack ...

Code - Python: [Select]
  1. __codehimbelonga__ = 'KDUB'
  2.  
  3. import random
  4. import string
  5.  
  6.  
  7. def passGen(code_len=8):
  8.     seed = string.ascii_letters + string.punctuation + string.digits
  9.     return ''.join(random.sample(seed * code_len, code_len))
  10.  
  11.  
  12.  

Code - Python: [Select]
  1. print(passGen())
  2.  
  3. print(passGen(4))
  4.  
  5. print(passGen(9))
  6.  
  7. print(passGen(15))
  8.  
  9. print(passGen(25))
  10.  

Code - Python: [Select]
  1. #C:\Python33\python.exe "D:/_Python Source/theSwamp/PasswordGen.py"
  2. '8I.Ap$~
  3. zR&^
  4. Hx4Uuuzgf
  5. C3T%jez'"~~.hNU
  6. RL:nTEKiMGUM$Ng6Pbq&gc3Lk
  7.  

Good fun!!
« Last Edit: August 29, 2013, 08:30:36 PM by Phred »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) Password Generator
« Reply #9 on: August 29, 2013, 06:58:54 PM »
more Hack.
optional to add punctuation : 1 = add , 0 = remove

Code - Python: [Select]
  1. __codehimbelonga__ = 'KDUB'
  2.  
  3. import random
  4. import string
  5.  
  6.  
  7. def passGen(code_len=8, punct=1):
  8.     if punct == 1:
  9.         seed = string.ascii_letters + string.punctuation + string.digits
  10.     else:
  11.         seed = string.ascii_letters + string.digits
  12.     return ''.join(random.sample(seed * code_len, code_len))
  13.  

Code - Python: [Select]
  1. print(passGen())
  2.  
  3. print(passGen(4))
  4.  
  5. print(passGen(10))
  6. print(passGen(10, 0))
  7.  
  8. print(passGen(15))
  9. print(passGen(15, 0))
  10.  
  11. print(passGen(25))
  12. print(passGen(25, 0))
  13.  

Code - Python: [Select]
  1. Y?XeE,tG
  2. q%\3
  3. (v?KE5$:Xq
  4. kWPo6dIFR9
  5. 7O[ap35]2'T,i28
  6. Y4T1coxasagEqh5
  7. _fu~bJ^tGFgS}U,M+n=5<I]<N
  8. II9DxIZpQ3qw0UpBDQojTWNP4
  9.  
« Last Edit: August 29, 2013, 08:31:00 PM by Phred »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: (Challenge) Password Generator
« Reply #10 on: August 29, 2013, 07:58:33 PM »
Attached is my take on the challenge.  :-)

Great idea Mark  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) Password Generator
« Reply #11 on: August 29, 2013, 08:14:19 PM »
Code - C#: [Select]
  1.   // Generate a new 12-character password with 1 non-alphanumeric character.
  2.   string password = Membership.GeneratePassword(12, 1)
  3.  
Namespace:  System.Web.Security
Assembly:     System.Web (in System.Web.dll)

http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (Challenge) Password Generator
« Reply #12 on: August 29, 2013, 08:26:39 PM »

More hack ..

Code - Javascript: [Select]
  1. function passGen(code_len)
  2. {
  3.   seed= "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  4.   result = "";
  5.   for(x=0;x<code_len;x++)
  6.   {
  7.     result += seed.charAt(Math.floor(Math.random() * 62));
  8.   }
  9.   return result;
  10. }
  11.  
  12.  
  13. passGen(25); // :->  'Kjqwcxzb2YQMrWoTVBJVk6zcw'
  14.  
  15.  

That's it .. I have work to do :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE3

  • Guest
Re: (Challenge) Password Generator
« Reply #13 on: August 29, 2013, 09:41:03 PM »
Code - C#: [Select]
  1. [CommandMethod("PASS")]
  2. public static void PasswordMaker()
  3. {
  4.     var doc = AcadApp.DocumentManager.MdiActiveDocument;
  5.     var editor = doc.Editor;
  6.     var passwordBase = Guid.NewGuid().ToString().Replace("-", "");
  7.     var password = new StringBuilder();
  8.     var random = new Random();
  9.     const int size = 12;
  10.     for (var i = 0; i < size; i++)
  11.     {
  12.         var ch = passwordBase[random.Next(0, passwordBase.Length)];
  13.         password.Append(ch);
  14.     }
  15.     for (var i = 0; i < password.Length; i++)
  16.     {
  17.         var next = random.Next(i, password.Length);
  18.         var s = password[next].ToString(CultureInfo.InvariantCulture);
  19.         password = password.Replace(s, s.ToUpper());
  20.     }
  21.     editor.WriteMessage("\nPassword: {0} \n", password.ToString());
  22. }

Quote
Command: pass
Password: 5b559DDbACCC
Password: 64E190E26FAF
Password: 4b88C7890744
Password: 2b1051CfD410
Password: 4D80De0914F3
Password: f75fD4348234
Password: D8D4849cD0F9
Password: 8d0d98424184
Password: 0B70B9705B30
Password: 8609f604a64B
Password: B6BF7377A70A

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: (Challenge) Password Generator
« Reply #14 on: August 29, 2013, 10:43:57 PM »
After some more tinkering (fixed some issues) I want to move on to creating "pronounceable" passwords and using SHA1 like PWGEN (the tool mentioned in the OP). This is fun! :D

Code: [Select]
3Afdfdb2
GhGP2A4e
d7jXm3Df
kjsicalG
dmd4XEew
7kWAZ432
ADj7ledf
4injDnks
ajBjel5d
3XLnq7IW
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org