Page 1 of 1 1
Topic Options
#213219 - 2018-03-05 04:09 PM Password generator script or command line app
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
Hi guys,

I have a project for which it would be nice to generate a "random" password I searched the board and found the post below. It works but is not ideal for my project. Did someone ever do anything with password generation in Kix and can someone recommend a command line tool they like? I found may command line tools but they all claim to be the best and the safest

XKCD_PW: Generate secure, relatively easy to remember passwords
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213220 - 2018-03-05 05:04 PM Re: Password generator script or command line app [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
Hmmm...easier than expected.

Nothing more than a random string generator but it works. Maybe I will add a parameter for simple and more complicated passwords but for now, I do not have a need for that.

 Code:
Break on

? RandomString(10)

Sleep 10

Function RandomString($lenght)
	Dim $characters, $i, $str

	$characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<>/{}=+&%$#@!*~"
	For $i = 1 to $lenght + 1
		$str = $str + SubStr($characters, Rnd(Len($characters)), 1)
	Next
	$RandomString = $str
EndFunction


Interpretation/translation of https://www.learnqtp.com/forums/Thread-VB-Script-random-string
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213221 - 2018-03-05 11:01 PM Re: Password generator script or command line app [Re: Mart]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4476
Loc: USA
Don'f forget to seed rnd.
Top
#213222 - 2018-03-06 09:06 AM Re: Password generator script or command line app [Re: Allen]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6374
Loc: Stuttgart, Germany
best seed everytime with @ticks before you call rnd()
_________________________



Top
#213223 - 2018-03-06 09:44 AM Re: Password generator script or command line app [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
I was thinking about that but when I use SRND to seed RND like shown below I get 1 string that has 10 characters. The other four are the same with extra characters added at the end to match the length specified. Without SRND I get five completely different strings so I took it out.

Seeding with @MSECS or @TICKS does not make any difference.

 Code:
Break on

? RandomString(10)
? RandomString(12)
? RandomString(14)
? RandomString(16)
? RandomString(18)

Sleep 10

Function RandomString($length)
	;Define variables
	Dim $characters, $i, $str
	
	;Set characters to use in random string
	$characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789<>/{}=+&%$#@!*~"
	
	;Seed the random number generator
	SRnd(@MSECS)
	
	;Loop to create random string until the string has the same length as specified
	For $i = 1 to $length + 1
		;Add next character to random string
		$str = $str + SubStr($characters, Rnd(Len($characters)), 1)
	Next
		
	$RandomString = $str
EndFunction
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#213224 - 2018-03-06 10:18 AM Re: Password generator script or command line app [Re: Mart]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1869
Loc: Hilversum, The Netherlands

;\)

Top
#213225 - 2018-03-07 12:02 AM Re: Password generator script or command line app [Re: Arend_]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2081
Loc: Tulsa, OK
Here is a very old script that I posted over on the kixforms forum 15 years ago. I'm sure some of the code could be extremely optimized by now, and I had to change some frames to group boxes to get it to display right, but it still works! haha

 Code:
;;;;;; ------------------------------------------------------------------------------------------------ 
;;;;;;   Description   :   Used to generate passwords.  Password will always contain a number. 
;;;;;;            Password will also always contain a special character if one is chosen. 
;;;;;;            Password will not contain L,l,I,i,0,O,o, as these are hard to read/enter. 
;;;;;;   Dependencies   :   KiX 4.10.0.0 or WKiX 4.11.0.0 and KiXForms 2.2.0.37 
;;;;;; ------------------------------------------------------------------------------------------------ 

Break On 

$Form = CreateObject("Kixtart.Form") 

; ------------------------------------------------------------------------------- 
;                                              Draw Form 
; ------------------------------------------------------------------------------- 
PopulateSetting() 

$Form.Width = 450 
$Form.Height = 170 
$Form.Caption = "Generate A Password" 
$Form.Backcolor = $form.rgb(180,200,180) 

$SpecialFrame = $Form.GroupBox("Special Chars") 
$SpecialFrame.Left = 5 
$SpecialFrame.Top = 10 
$SpecialFrame.Width = 100 
$SpecialFrame.Height = 70 

$CheckBox1 = $SpecialFrame.CheckBox("#") 
$CheckBox1.Left = 10 
$CheckBox1.Top = 20
$CheckBox1.Height = 10
$CheckBox1.Width = 30
$CheckBox1.value = $LastUsedOption1 
$CheckBox1.ToolTip = "Include in password" 

$CheckBox2 = $SpecialFrame.CheckBox("*") 
$CheckBox2.Left = 10 
$CheckBox2.Top = 35 
$CheckBox2.Height = 10 
$CheckBox2.Width = 30
$CheckBox2.value = $LastUsedOption2 
$CheckBox2.ToolTip = "Include in password" 

$CheckBox3 = $SpecialFrame.CheckBox("@@") 
$CheckBox3.Left = 10 
$CheckBox3.Top = 50 
$CheckBox3.Height = 10 
$CheckBox3.Width = 30
$CheckBox3.value = $LastUsedOption3 
$CheckBox3.ToolTip = "Include in password" 

$CheckBox4 = $SpecialFrame.CheckBox("$$") 
$CheckBox4.Left = 60 
$CheckBox4.Top = 20 
$CheckBox4.Height = 10 
$CheckBox4.Width = 30
$CheckBox4.value = $LastUsedOption4 
$CheckBox4.ToolTip = "Include in password" 

$CheckBox5 = $SpecialFrame.CheckBox("&&") 
$CheckBox5.Left = 60 
$CheckBox5.Top = 35 
$CheckBox5.Height = 10 
$CheckBox5.Width = 30
$CheckBox5.value = $LastUsedOption5 
$CheckBox5.ToolTip = "Include in password" 

$CheckBox6 = $SpecialFrame.CheckBox("!") 
$CheckBox6.Left = 60 
$CheckBox6.Top = 50 
$CheckBox6.Height = 10 
$CheckBox6.Width = 30
$CheckBox6.value = $LastUsedOption6 
$CheckBox6.ToolTip = "Include in password" 

$LengthFrame = $Form.GroupBox("Length") 
$LengthFrame.Left = 120 
$LengthFrame.Top = 10 
$LengthFrame.Width = 100 
$LengthFrame.Height = 70 

$LengthBox = $LengthFrame.TextBox($LastUsedLength)
$LengthBox.Height = 20
$LengthBox.Width = 30
$LengthBox.Center
$LengthBox.Alignment = 2
$LengthBox.ToolTip = "Length of password"

$PasswordFrame = $Form.GroupBox("Password") 
$PasswordFrame.Left = 235 
$PasswordFrame.Top = 10 
$PasswordFrame.Width = 200 
$PasswordFrame.Height = 70 

$PasswordBox = $PasswordFrame.TextBox
$PasswordBox.Height = 20
$PasswordBox.Width = 120
$PasswordBox.Left = 20
$PasswordBox.Top = 25
$PasswordBox.Alignment = 2
$PasswordBox.ToolTip = "Password"

$CopyButton = $PasswordFrame.ToolButton
$CopyButton.Icon = 7
$CopyButton.Left = $PasswordBox.Right + 8
$CopyButton.Top = $PasswordBox.Top
$CopyButton.Height = 20
$CopyButton.Width = 25
$CopyButton.OnClick = "CopyPassword()"
$CopyButton.Enabled = 0
$CopyButton.Backcolor = $form.rgb(200,200,200)
$CopyButton.ToolTip = "Copy to clipboard"

$GenerateButton = $Form.ToolButton 
$GenerateButton.Caption = "Generate" 
$GenerateButton.Icon = 10 
$GenerateButton.Left = 100 
$GenerateButton.Top = 95 
$GenerateButton.Width = 100 
$GenerateButton.Height = 25 
$GenerateButton.OnClick = "Generate()" 
$GenerateButton.Backcolor = $form.rgb(200,200,200) 

$ExitButton = $Form.ToolButton 
$ExitButton.Caption = "Exit" 
$ExitButton.Icon = 9 
$ExitButton.Left = 250 
$ExitButton.Top = 95 
$ExitButton.Width = 100 
$ExitButton.Height = 25 
$ExitButton.OnClick = "Quit()" 
$ExitButton.Backcolor = $form.rgb(200,200,200) 

$Form.Center 
$Form.Show 
While $Form.Visible 
  $=Execute($Form.DoEvents()) 
Loop 
Exit 1 

; ------------------------------------------------------------------------------- 
;                                                UDFs 
; ------------------------------------------------------------------------------- 
FUNCTION PopulateSetting() 
   $LastUsedLength = ReadValue("HKEY_Current_User\Software\KiXtart\PWordGen", "Length") 
   $LastUsedOption1 = ReadValue("HKEY_Current_User\Software\KiXtart\PWordGen", "Option1") 
   $LastUsedOption2 = ReadValue("HKEY_Current_User\Software\KiXtart\PWordGen", "Option2") 
   $LastUsedOption3 = ReadValue("HKEY_Current_User\Software\KiXtart\PWordGen", "Option3") 
   $LastUsedOption4 = ReadValue("HKEY_Current_User\Software\KiXtart\PWordGen", "Option4") 
   $LastUsedOption5 = ReadValue("HKEY_Current_User\Software\KiXtart\PWordGen", "Option5") 
   $LastUsedOption6 = ReadValue("HKEY_Current_User\Software\KiXtart\PWordGen", "Option6") 
   if $LastUsedLength = "" $LastUsedLength = 6 endif 
   if $LastUsedOption1 = "" $LastUsedOption1 = 1 endif 
   if $LastUsedOption2 = "" $LastUsedOption2 = 1 endif 
   if $LastUsedOption3 = "" $LastUsedOption3 = 1 endif 
   if $LastUsedOption4 = "" $LastUsedOption4 = 1 endif 
   if $LastUsedOption5 = "" $LastUsedOption5 = 1 endif 
   if $LastUsedOption6 = "" $LastUsedOption6 = 1 endif 
ENDFUNCTION 

FUNCTION Generate()
   if $Checkbox1.value = "1" $option1 = "35" else $option1 = "0" endif 
   if $Checkbox2.value = "1" $option2 = "42" else $option2 = "0"  endif 
   if $Checkbox3.value = "1" $option3 = "64" else $option3 = "0"  endif 
   if $Checkbox4.value = "1" $option4 = "36" else $option4 = "0"  endif 
   if $Checkbox5.value = "1" $option5 = "38" else $option5 = "0"  endif 
   if $Checkbox6.value = "1" $option6 = "33" else $option6 = "0"  endif 
   while $specials=0 or $numbers=0 
      $length = $Lengthbox.text 
      $password = pword($length) 
      if Instr ($password, "1") OR 
      Instr ($password, "2") OR 
      Instr ($password, "3") OR 
      Instr ($password, "4") OR 
      Instr ($password, "5") OR 
      Instr ($password, "6") OR 
      Instr ($password, "7") OR 
      Instr ($password, "8") OR 
      Instr ($password, "9") 
         $numbers = 1 
      else 
         $numbers = 0 
      endif 
      if (len ($option1) > 1 AND Instr ($password, Chr($option1))) OR 
      (len ($option2) > 1 AND Instr ($password, Chr($option2))) OR 
      (len ($option3) > 1 AND Instr ($password, Chr($option3))) OR 
      (len ($option4) > 1 AND Instr ($password, Chr($option4))) OR 
      (len ($option5) > 1 AND Instr ($password, Chr($option5))) OR 
      (len ($option6) > 1 AND Instr ($password, Chr($option6))) 
         $specials = 1 
      else 
         $specials = 0 
      endif 
      if $option1=0 and $option2=0 and $option3=0 and $option4=0 and $option5=0 and $option6=0 
         $specials = 1 
      endif 
   loop 
   $PasswordBox.Text = $Password 
   $CopyButton.Enabled = 1 
   $numbers = 0 
   $specials = 0 
   $null = WriteValue ("HKEY_Current_User\Software\KiXtart\PWordGen", "Length", $length, "REG_SZ") 
   $null = WriteValue ("HKEY_Current_User\Software\KiXtart\PWordGen", "Option1", $Checkbox1.value, "REG_DWORD") 
   $null = WriteValue ("HKEY_Current_User\Software\KiXtart\PWordGen", "Option2", $Checkbox2.value, "REG_DWORD") 
   $null = WriteValue ("HKEY_Current_User\Software\KiXtart\PWordGen", "Option3", $Checkbox3.value, "REG_DWORD") 
   $null = WriteValue ("HKEY_Current_User\Software\KiXtart\PWordGen", "Option4", $Checkbox4.value, "REG_DWORD") 
   $null = WriteValue ("HKEY_Current_User\Software\KiXtart\PWordGen", "Option5", $Checkbox5.value, "REG_DWORD") 
   $null = WriteValue ("HKEY_Current_User\Software\KiXtart\PWordGen", "Option6", $Checkbox6.value, "REG_DWORD") 
ENDFUNCTION 

FUNCTION Pword($length) 
   dim $seed, $length, $i, $chr
   $seed = 5000
   $seedjump = 1000
   $length = val($length)
   for $i = 1 to $length
      $chr = random(33,126,$seed) $seed = $seed - $seedjump
         select
            case $i = 1
               while $chr >= 48 and $chr <=57
                  $chr = random(33,126,$seed) $seed = $seed + $seedjump
               loop
            case $i = $length
               while $chr >= 48 and $chr <=57
                  $chr = random(33,126,$seed) $seed = $seed - $seedjump
               loop
         endselect
      IF ($chr = $option1 OR $chr = $option2 OR $chr = $option3 OR $chr = $option4 OR $chr = $option5 OR $chr = $option6) OR
      (($chr >= 49 AND $chr <= 57) OR ($chr >= 65 AND $chr <= 72) OR ($chr >= 74 AND $chr <= 75) OR
      ($chr >= 77 AND $chr <= 78) OR ($chr >= 80 AND $chr <= 90) OR ($chr >= 97 AND $chr <= 104) OR
      ($chr >= 106 AND $chr <= 107) OR ($chr >= 109 AND $chr <= 110) OR ($chr >= 112 AND $chr <= 122))
         $pword = $pword + chr($chr)
      ELSE
         $i = LEN ($pword)
      ENDIF
   next
ENDFUNCTION

FUNCTION random($min, $max, optional $seed) 
   DIM $i, $burn, $nul 
   srnd((-1)*@ticks*(val($seed)+1)) 
   $burn = rnd(50) 
   for $i = 1 to $burn 
      $nul = rnd($max) 
   next 
   $random = rnd($max) 
   while $random < $min or $random > $max 
      $random = rnd($max)    
   loop    
ENDFUNCTION 

FUNCTION CopyPassword() 
   $PasswordBox.SelStart  = 0 
   $PasswordBox.SelLength = -1 
   $PasswordBox.Copy 
ENDFUNCTION


Edited by ShaneEP (2018-03-07 12:10 AM)
Edit Reason: Saw some variables in quotes and just couldn't take it...

Top
#213229 - 2018-03-09 07:23 PM Re: Password generator script or command line app [Re: ShaneEP]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11575
Loc: CA
Hi Mart

There is a very awesome one created by Richard H


Flexible password generator
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=158693#Post158693

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=202723

Top
#213233 - 2018-03-12 09:00 AM Re: Password generator script or command line app [Re: NTDOC]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
 Originally Posted By: NTDOC

...

There is a very awesome one created by Richard H

Flexible password generator
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=158693#Post158693

...


Wow that's an oldie. I did not even remember that one. Reading some of the post (and discovering I even posted there myself) some bells started ringing and I remember using this back then. Not sure what happened. I guess changing jobs and getting 12 year older in the mean time sort of got in the way......
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 166 anonymous users online.
Newest Members
Romanc, Neurosine, Mads_H, Michael78, PaulBesafeglobal
17664 Registered Users

Generated in 0.04 seconds in which 0.017 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org