Password generator: Difference between revisions

added RPL
mNo edit summary
(added RPL)
 
(15 intermediate revisions by 12 users not shown)
Line 33:
<!-- or zed, on the other side of the pond. -->
<br><br>
 
=={{header|6502 Assembly}}==
Unfortunately, easy6502 cannot display text, but it does have a random number generator, so this example merely contains the logic for generating the password itself. The screen can only display colored pixels, and the top 4 bytes are masked off, so this is just a visual aid to show the process in action. The X register is loaded with the password's length (in this case, 20 characters, not counting the null terminator.)
<syntaxhighlight lang="6502asm">LDY #0
LDX #20
LOOP:
LDA $FE ;load a random byte
BMI LOOP ;IF GREATER THAN 7F, ROLL AGAIN
CMP #$21 ;ASCII CODE FOR !
BCC LOOP
CMP #$5C
BEQ LOOP ;NO \
CMP #$60
BEQ LOOP ;NO `
;else, must be a good character
STA $0200,Y
INY
DEX
BNE LOOP
BRK ;end program</syntaxhighlight>
 
{{out}}
Code was executed three times and generated the following passwords:
<pre>vPX[d5gUY_5lUj[bNDS1
hY+%]lM*j~1Z4YG!0X0<
v}N|4dK(b71qgi-gGwkq</pre>
 
=={{header|8086 Assembly}}==
Line 41 ⟶ 67:
Help is printed when no arguments are given.
 
<langsyntaxhighlight lang="asm"> cpu 8086
bits 16
;;; MS-DOS syscalls
Line 314 ⟶ 340:
lmask: resb 1 ; Mask for random number generation
rnddat: resb 4 ; RNG state
buffer: resb 257 ; Space to store password</langsyntaxhighlight>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">BYTE FUNC GetNumParam(CHAR ARRAY text BYTE min,max)
BYTE res
 
DO
PrintF("Input %S (%B-%B): ",text,min,max)
res=InputB()
UNTIL res>=min AND res<=max
OD
RETURN (res)
 
BYTE FUNC GetBoolParam(CHAR ARRAY text)
CHAR ARRAY s(255)
 
DO
PrintF("%S? (Y/N): ",text)
InputS(s)
IF s(0)=1 THEN
IF s(1)='y OR s(1)='Y THEN
RETURN (1)
ELSEIF s(1)='n OR s(1)='N THEN
RETURN (0)
FI
FI
OD
RETURN (0)
 
PROC Shuffle(CHAR ARRAY s)
BYTE i,j
CHAR tmp
 
i=s(0)
WHILE i>1
DO
j=Rand(i)+1
tmp=s(i) s(i)=s(j) s(j)=tmp
i==-1
OD
RETURN
 
BYTE FUNC Contains(CHAR ARRAY s CHAR c)
BYTE i
 
IF s(0)=0 THEN
RETURN (0)
FI
FOR i=1 TO s(0)
DO
IF s(i)=c THEN
RETURN (1)
FI
OD
RETURN (0)
 
CHAR FUNC RandChar(CHAR ARRAY s,unsafe)
BYTE len
CHAR c
 
len=s(0)
DO
c=s(Rand(len)+1)
UNTIL Contains(unsafe,c)=0
OD
RETURN (c)
 
PROC Generate(CHAR ARRAY res BYTE len,safe)
DEFINE PTR="CARD"
CHAR ARRAY st,
upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ",
lower="abcdefghijklmnopqrstuvwxyz",
numbers="0123456789",
special="!""#$%&'()*+,-./:;<=>?@[]^_|",
unsafe="Il1O05S2Z"
PTR ARRAY sets(4)
BYTE i
 
sets(0)=upper sets(1)=lower
sets(2)=numbers sets(3)=special
 
res(0)=len
FOR i=1 TO len
DO
IF safe THEN
res(i)=RandChar(sets(i MOD 4),unsafe)
ELSE
res(i)=RandChar(sets(i MOD 4),"")
FI
OD
Shuffle(res)
RETURN
 
PROC PrintHelp()
PutE()
PrintE("Program generates random passwords")
PrintE("containing at least one upper-case")
PrintE("letter, one lower-case letter, one")
PrintE("digit and one special character.")
PrintE("It is possible to exclude visually")
PrintE("similar characters Il1O05S2Z.")
PutE()
RETURN
 
PROC Main()
BYTE len,count,safe,i,again,help
CHAR ARRAY password(255)
 
help=GetBoolParam("Show help")
IF help THEN
PrintHelp()
FI
 
DO
len=GetNumParam("length of password",4,30)
safe=GetBoolParam("Exclude similar chars")
count=GetNumParam("number of passwords",1,10)
PutE()
FOR i=1 TO count
DO
Generate(password,len,safe)
PrintF("%B. %S%E",i,password)
OD
PutE()
again=GetBoolParam("Generate again")
UNTIL again=0
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Password_generator.png Screenshot from Atari 8-bit computer]
<pre>
Show help? (Y/N): Y
 
Program generates random passwords
containing at least one upper-case
letter, one lower-case letter, one
digit and one special character.
It is possible to exclude visually
similar characters Il1O05S2Z.
 
Input length of password (4-30): 25
Exclude similar chars? (Y/N): Y
Input number of passwords (1-10): 6
 
1. 'Eo4qRf3379LF;-D&|s8bdaC+
2. L'3nw+N94J9tw*Bx=vR9+6L.p
3. @7uAAjj3"Vi@r$E767'iE;Fm3
4. 3y)^4Lb9f8^oVT_]nVK33n>Nr
5. vi4>Xv46G(eK<P6dCq;#zU6-9
6. ^-/MwtrpvzW7;K36Y7jJ_8X8*
 
Generate again? (Y/N): N
</pre>
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Numerics.Discrete_Random;
with Ada.Strings.Fixed;
with Ada.Command_Line;
Line 508 ⟶ 686:
end loop;
 
end Mkpw;</langsyntaxhighlight>
{{out}}
<pre>$ ./mkpw count 8 length 22 safe
Line 520 ⟶ 698:
+@pyJ'3YQ'%~9?Tm/BHk?A</pre>
 
=={{header|Applesoft BASIC}}==
<syntaxhighlight lang="applesoft">1 N=1
2 L=8
3 M$=CHR$(13)
4 D$=CHR$(4)
5 S$(0)="S"
6 F$="A FILE"
7 C$(1)=" (CURRENT OPTION)"
8 DEF FN R(T)=ASC(MID$(G$(T),INT(RND(1)*LEN(G$(T))+1),1))
9 GOSUB 750
10 FOR Q = 0 TO 1 STEP 0
20 GOSUB 50CHOOSE
30 NEXT Q
40 END
 
REM *** CHOOSE ***
50 PRINT M$M$"1 GEN 2 DISP 3 FILE 4 LEN 5 NUM 6 SEED"
60 PRINT "7 CHR 8 HELP 9 QUIT "CHR$(10)"CHOOSE AN OPTION: ";
70 GET K$
75 IF K$ > CHR$(95) THEN K$ = CHR$(ASC(K$) - 32)
80 PRINT K$
85 ON VAL(K$) GOTO 100,200,300,400,500,600,700,800,900
90 GOTO 210OPTIONS
 
REM *** GENERATE ***
100 PRINT M$
105 IF L > 32 THEN PRINT "UM... OK, THIS MIGHT TAKE A BIT."M$
110 GOSUB 340OPEN
115 FOR P=1 TO N
120 P$=""
125 FOR I=1 TO L
135 P$=P$+CHR$(FNR(I*(I<5)))
140 NEXT I
REM SHUFFLE FIRST 4
150 FOR I = 1 TO 4
151 C$=MID$(P$,I,1)
152 J=INT(RND(1)*L)+1
153 H$=MID$(P$,J,1)
154 P$=MID$(P$,1,J-1)+C$+MID$(P$,J+1,L)
155 P$=MID$(P$,1,I-1)+H$+MID$(P$,I+1,L)
156 NEXT I
180 PRINT P$
185 NEXT P
190 GOTO 380CLOSE
 
REM *** DISPLAY ***
200 C = 0
REM *** OPTIONS ***
210 HOME
215 PRINT "PASSWORD GENERATOR"M$M$
220 PRINT "1. GENERATE "N" PASSWORD"S$(N=1)M$
225 PRINT "2. DISPLAYED"C$(C=0)M$" OR"
230 PRINT "3. WRITTEN TO "F$C$(C=1)M$
235 PRINT "4. SPECIFY THE PASSWORD LENGTH = "L;M$
240 PRINT "5. SPECIFY THE NUMBER OF PASSWORDS TO"M$TAB(31)"GENERATE"
245 PRINT "6. SPECIFY A SEED VALUE"M$
250 PRINT "7. EXCLUDE VISUALLY SIMILAR CHARACTERS"M$
255 PRINT "8. HELP AND OPTIONS"
260 RETURN
 
REM *** WRITE TO A FILE ***
300 C = 1
310 GOTO 210OPTIONS
REM *** OPEN A FILE ***
340 IF NOT C THEN RETURN
345 PRINT D$"OPEN "F$"
350 PRINT D$"CLOSE"F$
355 PRINT D$"DELETE "F$
360 PRINT D$"OPEN "F$
365 PRINT D$"WRITE "F$
370 RETURN
REM *** CLOSE A FILE ***
380 IF NOT C THEN RETURN
385 PRINT D$"CLOSE"F$
390 RETURN
 
REM *** SET PASSWORD LENGTH ***
400 PRINT M$
410 FOR I = 0 TO 1 STEP 0
420 INPUT "ENTER A NUMBER FROM 4 TO 255 TO SPECIFY THE PASSWORD LENGTH = ";L
430 IF L >= 4 AND L < 256 THEN RETURN
440 PRINT "?OUT OF RANGE"
450 NEXT I
 
REM *** SET NUMBER OF PASSWORDS TO GENERATE ***
500 PRINT M$
510 FOR I = 0 TO 1 STEP 0
520 INPUT "ENTER A NUMBER FROM 1 AND UP TO SPECIFY THE NUMBER OF PASSWORDS TO GENERATE: ";N
530 IF N >= 1 THEN RETURN
540 PRINT "?OUT OF RANGE."
550 NEXT I
 
REM *** SET A SEED VALUE ***
600 PRINT M$
610 INPUT "ENTER A SEED VALUE: ";S%
620 PRINT RND(S%)
630 RETURN
 
REM *** EXCLUDE ***
700 PRINT M$
705 INPUT "ENTER CHARACTERS TO EXCLUDE:";E$
REM *** GROUPS ***
REM ALWAYS EXCLUDE BACKSLASH AND BACKTICK (GRAVE)
710 E$=CHR$(92)+CHR$(96)+E$
711 FOR G = 1 TO 4
712 G$(G) = ""
713 NEXT G
720 FOR G = 1 TO 2
721 FOR K = ASC("A") + (G - 1) * 32 TO ASC("Z") + (G - 1) * 32
722 GOSUB 770ADD
723 NEXT K, G
730 FOR K = 33 TO 64
731 G = 3 + (K < ASC(STR$(0)) OR K > ASC(STR$(9)))
732 GOSUB 770ADD
733 NEXT K
734 FOR K = 91 TO 96
735 GOSUB 770ADD
736 NEXT K
737 FOR K = 123 TO 126
738 GOSUB 770ADD
739 NEXT K
740 G$(0) = ""
741 FOR G = 1 TO 4
742 IF LEN(G$(G)) THEN G$(0) = G$(0) + G$(G) : NEXT G : GOTO 800HELP
743 ?"THERE MUST BE AT LEAST ONE CHARUNRACTER IN EACH GROUP"
744 GOTO 705
REM *** DEFAULT (QUICK) ***
750 G$(1)="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
751 FOR I=97TO122:G$(2)=G$(2)+CHR$(I):NEXT
753 G$(3)="0123456789"
754 G$(4)="!"+CHR$(34)+"#$%&'()*+,-./:;<=>?@"+CHR$(91)+"]^"+CHR$(95)
755 FOR I=123TO126:G$(4)=G$(4)+CHR$(I):NEXTI
756 G$(0)=G$(0)+G$(1)+G$(2)+G$(3)
757 GOTO 210OPTIONS
REM *** ADD TO GROUP
770 C$ = CHR$(K)
775 FOR E = 1 TO LEN(E$)
780 IF C$ <> MID$(E$,E,1) THEN NEXT E : G$(G)=G$(G)+C$ : ?C$;
790 RETURN
 
REM *** HELP ***
800 HOME
805 PRINT "GENERATE PASSWORDS CONTAINING RANDOM"
810 PRINT "ASCII CHARACTERS FROM THESE GROUPS:"M$
815 PRINT " LOWERCASE UPPERCASE DIGIT OTHER"M$
820 PRINT " "LEFT$(G$(2),9)TAB(13)LEFT$(G$(1),9)TAB(23)LEFT$(G$(3),5)TAB(29)LEFT$(G$(4),11)
825 PRINT " "MID$(G$(2),10,9)TAB(13)MID$(G$(1),10,9)TAB(23)MID$(G$(3),6,5)TAB(29)MID$(G$(4),12,11)
826 PRINT " "MID$(G$(2),19,9)TAB(13)MID$(G$(1),19,9)TAB(29)MID$(G$(4),23,15)M$
840 PRINT "YOU MAY CHOOSE THE PASSWORD LENGTH, AND"
845 PRINT "HOW MANY PASSWORDS TO GENERATE. IT IS"
850 PRINT "ENSURED THAT THERE IS AT LEAST ONE"
855 PRINT "CHARACTER FROM EACH OF THE GROUPS IN"
860 PRINT "EACH PASSWORD. THERE IS AN OPTION TO"
865 PRINT "EXCLUDE VISUALLY SIMILAR CHARACTERS."
870 RETURN
 
REM *** QUIT ***
900 Q = 1
910 VTAB 23
920 RETURN</syntaxhighlight>
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">lowercase: `a`..`z`
uppercase: `A`..`Z`
digits: `0`..`9`
Line 556 ⟶ 894:
loop 1..10 'x [
print generate to :integer first arg
]</langsyntaxhighlight>
 
{{out}}
Line 574 ⟶ 912:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f PASSWORD_GENERATOR.AWK [-v mask=x] [-v xt=x]
#
Line 672 ⟶ 1,010:
printf("example: %s -v mask=%s -v xt=%s\n",cmd,mask,xt)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 684 ⟶ 1,022:
 
=={{header|C}}==
<syntaxhighlight lang="c">
<lang c>
#include <stdio.h>
#include <stdlib.h>
Line 811 ⟶ 1,149:
return 0;
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 825 ⟶ 1,163:
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 899 ⟶ 1,237:
return new string(password);
}
}</langsyntaxhighlight>
{{out}}
<pre>PASSGEN -l:12 -c:6
Line 910 ⟶ 1,248:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <string>
#include <algorithm>
Line 964 ⟶ 1,302:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 989 ⟶ 1,327:
<b>module.ceylon</b>:
 
<langsyntaxhighlight lang="ceylon">
module rosetta.passwordgenerator "1.0.0" {
import ceylon.random "1.2.2";
}
 
</syntaxhighlight>
</lang>
 
<b>run.ceylon:</b>
 
<langsyntaxhighlight lang="ceylon">
import ceylon.random {
DefaultRandom,
Line 1,131 ⟶ 1,469:
Character[] filterCharsToExclude(Character[] chars, Character[] charsToExclude)
=> chars.filter((char) => ! charsToExclude.contains(char)).sequence();
</syntaxhighlight>
</lang>
 
 
Line 1,171 ⟶ 1,509:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(ns pwdgen.core
(:require [clojure.set :refer [difference]]
[clojure.tools.cli :refer [parse-opts]])
Line 1,209 ⟶ 1,547:
(if (:help options) (println summary)
(dotimes [n (:count options)]
(println (apply str (generate-password options)))))))</langsyntaxhighlight>
 
{{out}}
Line 1,233 ⟶ 1,571:
Note that on line 220, the <code>CLR</code> statement is called prior to restarting the program to avoid a <code>?REDIM'D ARRAY ERROR</code> if line 85 should execute. By default, single dimension arrays do not need to be DIMensioned if kept to 11 elements (0 through 10) or less. Line 85 checks for this.
 
<langsyntaxhighlight lang="gwbasic">1 rem password generator
2 rem rosetta code
10 g$(1)="abcdefghijklmnopqrstuvwxyz"
Line 1,295 ⟶ 1,633:
610 print "Press any key to begin."
615 get k$:if k$="" then 615
620 return</langsyntaxhighlight>
 
{{out}}
Line 1,351 ⟶ 1,689:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">
(defvar *lowercase* '(#\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
#\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z))
Line 1,398 ⟶ 1,736:
(loop for x from 1 to count do
(print (generate-password len human-readable)))))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,411 ⟶ 1,749:
 
=={{header|Crystal}}==
<langsyntaxhighlight Crystallang="crystal">require "random/secure"
 
special_chars = true
Line 1,482 ⟶ 1,820:
break if count <= 0
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,529 ⟶ 1,867:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule Password do
@lower Enum.map(?a..?z, &to_string([&1]))
@upper Enum.map(?A..?Z, &to_string([&1]))
Line 1,567 ⟶ 1,905:
end
 
Password.generator</langsyntaxhighlight>
 
{{out}}
Line 1,584 ⟶ 1,922:
=={{header|F_Sharp|F#}}==
===The function===
<langsyntaxhighlight lang="fsharp">
// A function to generate passwords of a given length. Nigel Galloway: May 2nd., 2018
let N = (set)"qwertyuiopasdfghjklzxcvbnm"
Line 1,595 ⟶ 1,933:
let fN n = not (Set.isEmpty (Set.intersect N n )||Set.isEmpty (Set.intersect I n )||Set.isEmpty (Set.intersect G n )||Set.isEmpty (Set.intersect E n ))
Seq.initInfinite(fun _->(set)(List.init n (fun _->L.[y.Next()%(Array.length L)])))|>Seq.filter fN|>Seq.map(Set.toArray >> System.String)
</syntaxhighlight>
</lang>
===A possible use===
Print 5 password of length 8
<langsyntaxhighlight lang="fsharp">
pWords 8 |> Seq.take 5 |> Seq.iter(printfn "%s")
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,612 ⟶ 1,950:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-01-23}}
<langsyntaxhighlight lang="factor">USING: arrays assocs combinators command-line continuations io
kernel math math.parser multiline namespaces peg.ebnf
prettyprint random sequences ;
Line 1,681 ⟶ 2,019:
[ parse-args gen-pwds ] [ 2drop usage print ] recover ;
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 1,703 ⟶ 2,041:
9L6Lqt|yh|
</pre>
 
 
=={{header|FreeBASIC}}==
{{trans|Run BASIC}}<syntaxhighlight lang="freebasic">Dim As String charS(4)
charS(1) = "0123456789"
charS(2) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
charS(3) = "abcdefghijklmnopqrstuvwxyz"
charS(4) = "!""#$%&'()*+,-./:;<=>?@[]^_{|}~"
charS(0) = charS(1) + charS(2) + charS(3) + charS(4)
 
 
Dim As Integer howBig, howMany
Do
Print !"------ Password Generator ------\n"
Input "Longitud de la contrase¤a (n>=4): ", howBig
If howBig < 1 Then Sleep: End
Input "Cantidad de contrase¤as (n>=1): ", howMany
Loop While howMany < 1
 
Print !"\nGeneradas"; howMany; " contrase¤as de"; howBig; " caracteres"
 
Dim As Integer i = 0
Dim As String password, Ok, w
While i < howMany
password = ""
Ok = "...."
For j As Integer = 1 To howBig
w = Mid(charS(0), Int(Rnd * Len(charS(0))) + 1, 1)
For k As Byte = 1 To 4
If Instr(charS(k), w) Then Ok = Left(Ok, k-1) + "*" + Mid(Ok, k+1)
Next k
password += w
Next j
If Ok = "****" Then
i += 1
Print Using "##. &"; i; password
End If
Wend
Sleep
</syntaxhighlight>
{{out}}
<pre>------ Password Generator ------
 
Longitud de la contraseña (n>=4): 5
Cantidad de contraseñas (n>=1): 2
 
Generadas 2 contraseñas de 5 caracteres
1. 1qU+,
2. v?X7s
</pre>
 
=={{header|FutureBasic}}==
This compiles as a standalone Mac application that meets all the task requirements and options. Screenshot of compiled app shows output.
<syntaxhighlight lang="futurebasic">
output file "Password Generator"
include "Tlbx GameplayKit.incl"
 
begin enum
_mApplication
_mFile
_mEdit
end enum
 
begin enum 1
_iSeparator
_iPreferences
end enum
 
begin enum
_iCreate
_iSeparator2
_iSave
_iPrint
_iSeparator4
_iClose
end enum
 
_window = 1
begin enum output 1
_passwordScroll
_passwordView
_offscreenPrintView
_optionsHelp
_checkOmitIs
_checkOmitOs
_checkOmitSs
_checkOmit2s
_charactersLongLabel
_passwordLengthField
_pwAmountLabel
_pwAmountField
_seedLabel
_seedField
_helpBtn
_bottomLine
_saveBtn
_printBtn
_createPasswordsBtn
end enum
 
_helpPopover = 2
begin enum 1
_popoverLabel
end enum
 
_savePanel = 1
_pwLenAlert = 2
 
 
void local fn BuildMenus
// application
menu _mApplication, _iSeparator
menu _mApplication, _iPreferences,, @"Preferences…", @","
// file
menu _mFile, -1,, @"File"
menu _mFile, _iCreate,, @"Create passwords", @"p"
menu _mFile, _iSeparator2
menu _mFile, _iSave,, @"Save", @"s"
menu _mFile, _iPrint,, @"Print", @"p"
menu _mFile, _iSeparator4
menu _mFile, _iClose,, @"Close", @"w"
MenuItemSetAction( _mFile, _iClose, @"performClose:" )
editmenu _mEdit
end fn
 
void local fn BuildWindow
long tag
CGRect r = fn CGRectMake( 0, 0, 672, 460 )
window _window, @"Rosetta Code Password Generator", r//, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
WindowSetContentMinSize( _window, fn CGSizeMake(310,386) )
r = fn CGRectMake( 20, 73, 515, 370 )
scrollview _passwordScroll, r, NSLineBorder,,_window
ViewSetAutoresizingMask( _passwordScroll, NSViewWidthSizable + NSViewHeightSizable )
textview _passwordView, r, _passwordScroll,, _window
TextViewSetTextContainerInset( _passwordView, fn CGSizeMake( 10, 15 ) )
TextSetFontWithName( _passwordView, @"Menlo", 13.0 )
r = fn CGRectMake( -600, -600, 450, 405 )
textview _offscreenPrintView, r,,, _window
TextSetFontWithName( _offscreenPrintView, @"Menlo", 13.0 )
TextSetColor( _offscreenPrintView, fn ColorBlack )
TextViewSetBackgroundColor( _offscreenPrintView, fn ColorWhite )
r = fn CGRectMake( 547, 424, 60, 16 )
textlabel _optionsHelp, @"Exclude:", r, _window
r = fn CGRectMake( 607, 425, 41, 14 )
button _checkOmitIs, YES, NSControlStateValueOff, @"Il1", r, NSButtonTypeSwitch
ViewSetToolTip( _checkOmitIs, @"Omit similar characters I, l and 1." )
r = fn CGRectOffset( r, 0, -24 )
button _checkOmitOs, YES ,NSControlStateValueOff, @"O0", r, NSButtonTypeSwitch
ViewSetToolTip( _checkOmitOs, @"Omit similar characters O and 0." )
r = fn CGRectOffset( r, 0, -24 )
button _checkOmitSs, YES, NSControlStateValueOff, @"5S", r, NSButtonTypeSwitch
ViewSetToolTip( _checkOmitSs, @"Omit similar characters 5 and S." )
r = fn CGRectOffset( r, 0, -24 )
button _checkOmit2s, YES, NSControlStateValueOff, @"2Z", r, NSButtonTypeSwitch
ViewSetToolTip( _checkOmit2s, @"Omit similar characters 2 and Z." )
r = fn CGRectMake( 549, 322, 103, 16 )
textlabel _charactersLongLabel, @"Chars (4-50)", r, _window
r = fn CGRectMake( 549, 298, 103, 21 )
textfield _passwordLengthField, YES, @"25", r,_window
TextFieldSetBordered( _passwordLengthField, YES )
ControlSetAlignment(_passwordLengthField, NSTextAlignmentCenter )
ControlSetFormat( _passwordLengthField, @"0123456789", YES, 2, 0 )
ViewSetToolTip( _passwordLengthField, @"Set password length from 4 to 50." )
r = fn CGRectMake( 549, 263, 103, 16 )
textlabel _pwAmountLabel, @"Passwords:", r, _window
r = fn CGRectMake( 549, 240, 103, 21 )
textfield _pwAmountField, YES, @"100", r,_window
TextFieldSetBordered( _pwAmountField, YES )
ControlSetAlignment( _pwAmountField, NSTextAlignmentCenter )
ControlSetFormat( _pwAmountField, @"0123456789", YES, 4, 0 )
ViewSetToolTip( _pwAmountField, @"Enter number of passwords to generate." )
r = fn CGRectMake( 549, 205, 103, 16 )
textlabel _seedLabel, @"Seed value:", r, _window
r = fn CGRectMake( 549, 182, 103, 21 )
textfield _seedField, YES, , r,_window
TextFieldSetBordered( _seedField, YES )
ControlSetAlignment(_seedField, NSTextAlignmentCenter )
ControlSetFormat( _seedField, @"0123456789", YES, 6, 0 )
ViewSetToolTip( _seedField, @"Enter optional random seed number." )
for tag = _optionsHelp to _seedField
ViewSetAutoresizingMask( tag, NSViewMinXMargin + NSViewMinYMargin )
next
r = fn CGRectMake( 631, 70, 25, 25 )
button _helpBtn, YES,,, r, NSButtonTypeMomentaryLight, NSBezelStyleHelpButton, _window
ViewSetToolTip( _helpBtn, @"Click for application help instructions." )
ViewSetAutoresizingMask( _helpBtn, NSViewMinXMargin + NSViewMaxYMargin )
r = fn CGRectMake( 20, 55, 632, 5 )
box _bottomline,, r, NSBoxSeparator
ViewSetAutoresizingMask( _bottomline, NSViewWidthSizable + NSViewMaxYMargin )
r = fn CGRectMake( 20, 15, 62, 32 )
button _printBtn, YES, , @"Print…", r, NSButtonTypeMomentaryLight, NSBezelStyleRegularSquare, _window
ViewSetAutoresizingMask( _printBtn, NSViewMaxXMargin + NSViewMaxYMargin )
r = fn CGRectMake( 91, 15, 62, 32 )
button _saveBtn, YES, , @"Save…", r, NSButtonTypeMomentaryLight, NSBezelStyleRegularSquare, _window
ViewSetAutoresizingMask( _saveBtn, NSViewMaxXMargin + NSViewMaxYMargin )
r = fn CGRectMake( 522, 15, 131, 32 )
button _createPasswordsBtn, YES, , @"Create passwords", r, NSButtonTypeMomentaryLight, NSBezelStyleRegularSquare, _window
ViewSetAutoresizingMask( _createPasswordsBtn, NSViewMinXMargin + NSViewMaxYMargin )
end fn
 
void local fn BuildPopover
CFStringRef helpText = @"This application generates randomized passwords from 4 to 50 characters in length. "
helpText = fn StringByAppendingString( helpText, @"Theoretically, the number generated is limited only by system memory.\n\n" )
helpText = fn StringByAppendingString( helpText, @"Passwords will contain at least one each of the following character types:\n" )
helpText = fn StringByAppendingString( helpText, @"\tLowercase letters\t\t: a -> z\n" )
helpText = fn StringByAppendingString( helpText, @"\tUppercase letters\t\t: A -> Z\n" )
helpText = fn StringByAppendingString( helpText, @"\tNumbers\t\t\t\t: 0 -> 9\n" )
helpText = fn StringByAppendingString( helpText, @"\tSpecial characters\t: !\"#$%&'()*+,-./:;<=>?@[]^_{|}~\n\n" )
helpText = fn StringByAppendingString( helpText, @"You can use checkboxes to exclude visually similar characters: Il1 O0 5S 2Z.\n\n" )
helpText = fn StringByAppendingString( helpText, @"This application offers two automatic levels of randomization. However you are " )
helpText = fn StringByAppendingString( helpText, @"welcome to enter a custom randomizer seed number in the box provided.\n\n" )
helpText = fn StringByAppendingString( helpText, @"Passwords can be copied to the pasteboard, saved to a text file, or printed." )
popover _helpPopover, (0,0,395,365), NSPopoverBehaviorTransient
textlabel _popoverLabel, helpText, (10,10,375,345)
end fn
 
void local fn OutOfBoundsAlert
CFStringRef alertStr = @"Passwords must be at least four characters long, but no more than 50 characters."
alert -_pwLenAlert,, @"Password length is out of bounds", alertStr, @"Okay", YES
AlertButtonSetKeyEquivalent( _pwLenAlert, 1, @"\e" )
AlertSetStyle( _pwLenAlert, NSAlertStyleWarning )
alert _pwLenAlert
end fn
 
 
local fn BuildPassword as CFStringRef
long i
CFArrayRef charArr = fn AppProperty( @"charArray" )
CFStringRef numbers = charArr[0]
CFStringRef uppercase = charArr[1]
CFStringRef lowercase = charArr[2]
CFStringRef symbols = charArr[3]
// Omit confusing letters selected by user, if any
if ( fn ButtonState( _checkOmitIs ) == NSControlStateValueOn )
numbers = fn StringByReplacingOccurrencesOfString( numbers, @"1", @"" )
uppercase = fn StringByReplacingOccurrencesOfString( uppercase, @"I", @"" )
lowercase = fn StringByReplacingOccurrencesOfString( lowercase, @"l", @"" )
end if
if ( fn ButtonState( _checkOmitOs ) == NSControlStateValueOn )
numbers = fn StringByReplacingOccurrencesOfString( numbers, @"0", @"" )
uppercase = fn StringByReplacingOccurrencesOfString( uppercase, @"O", @"" )
end if
if( fn ButtonState( _checkOmitSs ) == NSControlStateValueOn )
numbers = fn StringByReplacingOccurrencesOfString( numbers, @"5", @"" )
uppercase = fn StringByReplacingOccurrencesOfString( uppercase, @"S", @"" )
end if
if ( fn ButtonState( _checkOmit2s ) == NSControlStateValueOn )
numbers = fn StringByReplacingOccurrencesOfString( numbers, @"2", @"" )
uppercase = fn StringByReplacingOccurrencesOfString( uppercase, @"Z", @"" )
end if
// Build string pool from other character sets
CFStringRef allChars = fn StringWithFormat( @"%@%@%@%@", numbers, uppercase, lowercase, symbols )
// Begin construction password string with single random character from each character set
randomize
CFMutableStringRef pwStr = fn MutableStringWithCapacity(0)
CFStringRef rndNumberChar = fn StringWithFormat( @"%c", fn StringCharacterAtindex( numbers, rnd( len( numbers ) -1 ) ) )
CFStringRef rndUCaseChar = fn StringWithFormat( @"%c", fn StringCharacterAtindex( uppercase, rnd( len( uppercase ) -1 ) ) )
CFStringRef rndLCaseChar = fn StringWithFormat( @"%c", fn StringCharacterAtindex( lowercase, rnd( len( lowercase ) -1 ) ) )
CFStringRef rndSymbolChar = fn StringWithFormat( @"%c", fn StringCharacterAtindex( symbols, rnd( len( symbols ) -1 ) ) )
// Add first four randomized characters to password string
MutableStringAppendString( pwStr, fn StringWithFormat( @"%@%@%@%@", rndNumberChar, rndUCaseChar, rndLCaseChar, rndSymbolChar ) )
// Build array of characters for shuffling
CFMutableArrayRef mutArr = fn MutableArrayWithCapacity(0)
for i = 0 to len(allChars) - 1
unichar tempUni = fn StringCharacterAtIndex( allChars, i )
CFStringRef s = fn StringWithFormat( @"%c", tempUni )
MutableArrayInsertObjectAtIndex( mutArr, s, i )
next
// Shuffle character array for randomness
CFArrayRef rndStrArr = fn GKRandomSourceArrayByShufflingObjectsInArray( fn GKRandomSourceInit, mutArr )
CFStringRef rndStr = fn ArrayComponentsJoinedByString( rndStrArr, @"" )
long pwLength = fn StringIntegerValue( fn ControlStringValue( _passwordLengthField ) )
// Subtract 4 for mandatory charaacters already set
rndStr = fn StringSubstringToIndex( rndStr, pwLength - 4 )
MutableStringAppendString( pwStr, rndStr )
end fn = pwStr
 
 
void local fn RandomizeWithSeed
CFStringRef seedStr = fn ControlStringValue( _seedField )
if ( len(seedStr) > 0 )
long seedNum = fn StringIntegerValue( seedStr )
randomize seedNum
else
exit fn
end if
end fn
 
 
void local fn CreatePasswords
NSInteger i
CFMutableStringRef passwords = fn MutableStringWithCapacity(0)
long numberNeeded = fn StringIntegerValue( fn ControlStringValue( _pwAmountField ) )
// Get length of password designated by user
long pwLength = fn StringIntegerValue( fn ControlStringValue( _passwordLengthField ) )
if ( pwLength > 50 ) or ( pwLength < 4 )
fn OutOfBoundsAlert : exit fn
end if
fn RandomizeWithSeed
for i = 1 to numberNeeded
MutableStringAppendString( passwords, fn StringWithFormat( @"%4d. %@%@\n", i, fn BuildPassword, @"\n" ) )
next
TextSetString( _passwordView, passwords )
end fn
 
 
void local fn SaveFile
savepanel -_savePanel, @"Save file...", @"public.plain-text",,,, _true
SavePanelSetCanCreateDirectories( _savePanel, YES )
SavePanelSetAllowedFileTypes( _savePanel, @[@"txt"] )
SavePanelSetExtensionHidden( _savePanel, NO )
// Run savepanel; action captured in fn DoDialog
savepanel _savePanel
end fn
 
 
void local fn SetViewText( url as CFURLRef )
CFStringRef tempStr = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
WindowSetTitleWithRepresentedURL( _window, url )
TextSetString( _passwordView, tempStr )
end fn
 
 
void local fn PrintView( tag as long )
TextSetString( _offscreenPrintView, fn TextString( tag ) )
ViewPrint( _offscreenPrintView )
end fn
 
// Build character arrays at launch and save as application property
void local fn CreateCharactersDictionary
CFArrayRef charArray = @[¬
@"0123456789",¬
@"ABCDEFGHIJKLMNOPQRSTUVWXYZ",¬
@"abcdefghijklmnopqrstuvwxyz",¬
@"!\"#$%&'()*+,-./:;<=>?@[]^_{|}~"]
AppSetProperty( @"charArray", charArray )
end fn
 
 
void local fn DoAppEvent( ev as long )
select (ev)
case _appDidFinishLaunching
fn CreateCharactersDictionary
fn BuildMenus
fn BuildPopover
fn BuildWindow
case _appShouldTerminateAfterLastWindowClosed
AppEventSetBool(YES)
end select
end fn
 
 
void local fn DoMenu( menuID as long, itemID as long )
select (menuID)
case _mApplication
select (itemID)
case _iPreferences // show preferences window
end select
case _mFile
select (itemID)
case _iCreate : fn CreatePasswords
case _iSave : fn SaveFile
case _iPrint : fn PrintView( _passwordView )
end select
end select
end fn
 
 
void local fn DoDialog( ev as NSInteger, tag as NSInteger, wnd as NSInteger, obj as CFTypeRef )
select ( ev )
case _btnClick
select ( tag )
case _createPasswordsBtn : fn CreatePasswords
case _saveBtn : fn SaveFile
case _printBtn : fn PrintView( _passwordView )
case _helpBtn : PopoverShow( _helpPopover, CGRectZero, _helpBtn, CGRectMaxXEdge )
end select
end select
end fn
 
on appEvent fn DoAppEvent
on menu fn DoMenu
on dialog fn DoDialog
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Password Generator.png]]
 
=={{header|Gambas}}==
'''[https:c/gambas-playground.proko.eu/?gist=0ef1242c761d8a39297fb913fc6a56c0 Click this link to run this code]'''
<langsyntaxhighlight lang="gambas">' Gambas module file
 
' INSTRUCTIONS
Line 1,775 ⟶ 2,540:
Print sPassword 'Print the password list
 
End</langsyntaxhighlight>
Output:
<pre>
Line 1,795 ⟶ 2,560:
 
=={{header|Go}}==
<syntaxhighlight lang="go">
<lang Go>
package main
 
Line 1,888 ⟶ 2,653:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,906 ⟶ 2,671:
The function <code>password</code> for given length and a list of char sets which should be included, generates random password.
 
<langsyntaxhighlight Haskelllang="haskell">import Control.Monad
import Control.Monad.Random
import Data.List
Line 1,925 ⟶ 2,690:
x <- uniform lst
xs <- shuffle (delete x lst)
return (x : xs)</langsyntaxhighlight>
 
For example:
Line 1,937 ⟶ 2,702:
User interface (uses a powerful and easy-to-use command-line [https://hackage.haskell.org/package/options-1.2.1.1/docs/Options.html option parser]).
 
<langsyntaxhighlight Haskelllang="haskell">import Options
 
data Opts = Opts { optLength :: Int
Line 1,963 ⟶ 2,728:
, "!\"#$%&'()*+,-./:;<=>?@[]^_{|}~" ]
 
visualySimilar = ["l","IOSZ","012","!|.,"]</langsyntaxhighlight>
 
{{Out}}
Line 2,016 ⟶ 2,781:
Implementation:
 
<langsyntaxhighlight Jlang="j">thru=: <. + i.@(+*)@-~
chr=: a.&i.
 
Line 2,038 ⟶ 2,803:
y must be at least 4 because
passwords must contain four different kinds of characters.
)</langsyntaxhighlight>
 
Example use (from J command line):
 
<langsyntaxhighlight Jlang="j"> pwgen'help'
[x] pwgen y - generates passwords of length y
optional x says how many to generate (if you want more than 1)
Line 2,056 ⟶ 2,821:
Oo?|2oc4yi
9V9[EJ:Txs
$vYd(>4L:m</langsyntaxhighlight>
 
=={{header|Java}}==
{{works with|Java|7}}
<langsyntaxhighlight lang="java">import java.util.*;
 
public class PasswordGenerator {
Line 2,125 ⟶ 2,890:
return sb.toString();
}
}</langsyntaxhighlight>
 
<pre>7V;m
Line 2,139 ⟶ 2,904:
 
=={{header|JavaScript}}==
<langsyntaxhighlight JavaScriptlang="javascript">String.prototype.shuffle = function() {
return this.split('').sort(() => Math.random() - .5).join('');
}
Line 2,192 ⟶ 2,957:
console.log( createPwd( {len: 20, num: 2}) );
console.log( createPwd( {len: 20, num: 2, noSims: false}) );
</syntaxhighlight>
</lang>
{{out}}<pre>
> Q^g"7
Line 2,200 ⟶ 2,965:
</pre>
 
 
=={{header|jq}}==
{{Works with|jq}}
 
'''Works with gojq, the Go implementation of jq'''
 
'''Adapted from [[#Julia|Julia]]'''
 
The following assumes that an external source of randomness such as /dev/urandom is available
and that jq is invoked along the lines of the following:
<pre>
< /dev/urandom tr -cd '0-9' | fold -w 1 | jq -MRnr -f password-generator.jq
</pre>
<syntaxhighlight lang="jq">
# Output: a prn in range(0;$n) where $n is `.`
def prn:
if . == 1 then 0
else . as $n
| ([1, (($n-1)|tostring|length)]|max) as $w
| [limit($w; inputs)] | join("") | tonumber
| if . < $n then . else ($n | prn) end
end;
 
# Input: an array
# Output: an array, being a selection of $k elements from . chosen with replacement
def prns($k):
. as $in
| length as $n
| [range(0; $k) | $in[$n|prn]];
 
def knuthShuffle:
length as $n
| if $n <= 1 then .
else {i: $n, a: .}
| until(.i == 0;
.i += -1
| (.i + 1 | prn) as $j
| .a[.i] as $t
| .a[.i] = .a[$j]
| .a[$j] = $t)
| .a
end;
 
# Generate a single password of length $len >= 4;
# certain confusable characters are only allowed iff $simchars is truthy.
def passgen($len; $simchars):
def stoa: explode | map([.]|implode);
if $len < 4 then "length must be at least 4" | error
else
{ DIGIT: ("0123456789" | stoa),
UPPER: [range(65;91) | [.] | implode], # A-Z
LOWER: [range(97;123) | [.] | implode], # a-z
OTHER: ("!\"#$%&'()*+,-./:;<=>?@[]^_{|}~" | stoa) }
| if $simchars|not
then .DIGIT |= . - ["0", "1", "2", "5"]
| .UPPER |= . - ["O", "I", "Z", "S"]
| .LOWER |= . - ["l"]
end
| (reduce (.DIGIT, .UPPER, .LOWER, .OTHER) as $set ([];
. + ($set | prns(1)))) +
(.DIGIT + .UPPER + .LOWER + .OTHER | prns($len - 4))
| knuthShuffle
| join("")
end ;
 
def passgen($len):
passgen($len; true);
 
# Generate a stream of $npass passwords, each of length $len;
# certain confusable characters are only allowed iff $simchars is truthy.
def passgen($len; $npass; $seed; $simchars):
if ($seed | type) == "number" and $seed > 0 then $seed | prn else null end
| range(0; $npass)
| passgen($len; $simchars) ;
 
 
### Examples:
"Without restriction:", passgen(12; 5; null; true),
"",
"Certain confusable characters are disallowed:", passgen(12; 5; null; false)
</syntaxhighlight>
{{output}}
<pre>
Without restriction:
yT8+9t7=wfEn
#]j<HIpThJ6A
|~O{psk*[5)I
w_(N%QrI5:5#
$o3sfdKv"'9~
 
Certain confusable characters are disallowed:
>oXgj>H9wX^[
a^JR+v!bk6GU
7$~yp?YG]G|E
!/_MM_g.p{a4
iD?+xU+!A4]R
</pre>
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">function passgen(len::Integer; simchars::Bool=true)::String
if len < 4; error("length must be at least 4") end
# Definitions
Line 2,231 ⟶ 3,094:
end
 
passgen(stdout, 10, 12; seed = 1)</langsyntaxhighlight>
 
{{out}}
Line 2,248 ⟶ 3,111:
 
=={{header|Kotlin}}==
<langsyntaxhighlight Groovylang="groovy">// version 1.1.4-3
 
import java.util.Random
Line 2,438 ⟶ 3,301:
generatePasswords(pwdLen!!, pwdNum!!, toConsole, toFile!!)
}</langsyntaxhighlight>
 
Sample input and output:
Line 2,470 ⟶ 3,333:
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">function randPW (length)
local index, pw, rnd = 0, ""
local chars = {
Line 2,499 ⟶ 3,362:
os.exit()
end
for i = 1, arg[2] do print(randPW(tonumber(arg[1]))) end</langsyntaxhighlight>
Command line session:
<pre>>lua pwgen.lua
Line 2,517 ⟶ 3,380:
6lN9*Nx<</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">(* Length is the Length of the password, num is the number you want, \
 
<lang Mathematica>
(* Length is the Length of the password, num is the number you want, \
and similar=1 if you want similar characters, 0 if not. True and \
False, should work in place of 1/0 *)
Line 2,550 ⟶ 3,411:
]</syntaxhighlight>
]
</lang>
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import os, parseopt, random, sequtils, strformat, strutils
 
const Symbols = toSeq("!\"#$%&'()*+,-./:;<=>?@[]^_{|}~")
Line 2,652 ⟶ 3,512:
# Display the passwords.
for pw in passGen(passLength, count, seed, excludeSimilars):
echo pw</langsyntaxhighlight>
 
{{out}}
Line 2,665 ⟶ 3,525:
=={{header|OCaml}}==
 
<langsyntaxhighlight lang="ocaml">let lower = "abcdefghijklmnopqrstuvwxyz"
let upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let digit = "0123456789"
let other = "!\"034#$%&'()*+,-./:;<=>?@[]^_{|}~"
(* unconfuse syntax highlighter: " *)
 
let visually_similar = "Il1O05S2Z"
Line 2,722 ⟶ 3,581:
for i = 1 to !num do
print_endline (mk_pwd !len !readable)
done</langsyntaxhighlight>
 
{{out}}
Line 2,744 ⟶ 3,603:
=={{header|ooRexx}}==
{{trans||REXX}}
<langsyntaxhighlight lang="oorexx">/*REXX program generates a random password according to the Rosetta Code task's rules.*/
parse arg L N seed xxx dbg /*obtain optional arguments from the CL*/
casl= 'abcdefghijklmnopqrstuvwxyz' /*define lowercase alphabet. */
Line 2,841 ⟶ 3,700:
¦ dbg Schow count of characters in the 4 groups ¦
+-----------------------------------------------------------------------------+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~documentation ends on the previous line.~~~~~~~~~~~~~~~~~~~*/</langsyntaxhighlight>
{{out}}
<pre>D:\>rexx genpwd 12 4 33 , x
Line 2,866 ⟶ 3,725:
 
PARI/GP has a very good builtin random generator.
<langsyntaxhighlight lang="parigp">passwd(len=8, count=1, seed=0) =
{
if (len <= 4, print("password too short, minimum len=4"); return(), seed, setrand(seed));
Line 2,880 ⟶ 3,739:
}
 
addhelp(passwd, "passwd({len},{count},{seed}): Password generator, optional: len (min=4, default=8), count (default=1), seed (default=0: no seed)");</langsyntaxhighlight>
 
Output: ''passwd()''<pre>34K76+mB</pre>
Line 2,900 ⟶ 3,759:
 
=={{header|Pascal}}==
<syntaxhighlight lang="pascal">
<lang PASCAL>
program passwords (input,output);
 
Line 3,077 ⟶ 3,936:
end.
 
</syntaxhighlight>
</lang>
Useage for the output example: passwords --about -h --length=12 --number 12 --exclude
 
Line 3,112 ⟶ 3,971:
=={{header|Perl}}==
Use the module <tt>Math::Random</tt> for marginally better random-ness than the built-in function, but no warranty is expressed or implied, <i>caveat emptor</i>.
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 3,161 ⟶ 4,020:
[--help]
END
}</langsyntaxhighlight>
{{out}}
<pre>sc3O~3e0
Line 3,171 ⟶ 4,030:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>constant az = "abcdefghijklmnopqrstuvwxyz",
<span style="color: #000080;font-style:italic;">--with javascript_semantics -- not quite yet:</span>
AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (VALUECHANGED_CB not yet triggering)</span>
O9 = "1234567890",
<span style="color: #008080;">constant</span> <span style="color: #000000;">az</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"abcdefghijklmnopqrstuvwxyz"</span><span style="color: #0000FF;">,</span>
OT = "!\"#$%&'()*+,-./:;<=>?@[]^_{|}~"
<span style="color: #000000;">AZ</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"ABCDEFGHIJKLMNOPQRSTUVWXYZ"</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">O9</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"1234567890"</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">OT</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"!\"#$%&'()*+,-./:;&lt;=&gt;?@[]^_{|}~"</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">password</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">len</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">exclude</span><span style="color: #0000FF;">=</span><span style="color: #008000;">"Il1O05S2Z"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{},</span>
<span style="color: #000000;">S4</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">,{{</span><span style="color: #000000;">az</span><span style="color: #0000FF;">,</span><span style="color: #000000;">AZ</span><span style="color: #0000FF;">,</span><span style="color: #000000;">O9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">OT</span><span style="color: #0000FF;">},{</span><span style="color: #008000;">"out"</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">exclude</span><span style="color: #0000FF;">}})</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">pw</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">len</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">sel</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">shuffle</span><span style="color: #0000FF;">({</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">}&</span><span style="color: #7060A8;">sq_rand</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">len</span><span style="color: #0000FF;">-</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)))</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">len</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">S4c</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">S4</span><span style="color: #0000FF;">[</span><span style="color: #000000;">sel</span><span style="color: #0000FF;">[</span><span style="color: #000000;">c</span><span style="color: #0000FF;">]]</span>
<span style="color: #000000;">pw</span><span style="color: #0000FF;">[</span><span style="color: #000000;">c</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">S4c</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">S4c</span><span style="color: #0000FF;">))]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pw</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
function password(integer len, integer n, sequence exclude="Il1O05S2Z")
sequence res = {},
S4 = apply(true,filter,{{az,AZ,O9,OT},{"out"},{exclude}})
string pw = repeat(' ',len)
for i=1 to n do
sequence sel = shuffle({1,2,3,4}&sq_rand(repeat(4,len-4)))
for c=1 to len do
string S4c = S4[sel[c]]
pw[c] = S4c[rand(length(S4c))]
end for
res = append(res,pw)
end for
return res
end function
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">lenl</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">leng</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">numl</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">numb</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">dlg</span>
integer l = prompt_number("Password length(4..99):",{4,99}),
n = prompt_number("Passwords required(1..99):",{1,99})
<span style="color: #008080;">function</span> <span style="color: #000000;">valuechanged_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*leng|numb*/</span><span style="color: #0000FF;">)</span>
printf(1,"%s\n",join(password(l,n),"\n"))</lang>
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">leng</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">numb</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">password</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"&"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"&&"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (on p2js??)</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"SIZE"</span><span style="color: #0000FF;">,</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupRefresh</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">lenl</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"length(4..99)"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">leng</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"SPIN=YES,SPINMIN=4,SPINMAX=99"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">numl</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"number(1..99)"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">numb</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"SPIN=YES,SPINMIN=1,SPINMAX=99"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"FONTFACE=Courier"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetCallback</span><span style="color: #0000FF;">({</span><span style="color: #000000;">leng</span><span style="color: #0000FF;">,</span><span style="color: #000000;">numb</span><span style="color: #0000FF;">},</span><span style="color: #008000;">"VALUECHANGED_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"valuechanged_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">IupVbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">lenl</span><span style="color: #0000FF;">,</span><span style="color: #000000;">leng</span><span style="color: #0000FF;">,</span><span style="color: #000000;">numl</span><span style="color: #0000FF;">,</span><span style="color: #000000;">numb</span><span style="color: #0000FF;">},</span><span style="color: #008000;">"GAP=10,NORMALIZESIZE=VERTICAL"</span><span style="color: #0000FF;">),</span>
<span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})},</span><span style="color: #008000;">"MARGIN=5x5"</span><span style="color: #0000FF;">),</span>
<span style="color: #008000;">`TITLE="Password Generator"`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
{{out}}
With a length of 12 and generating 6 of them
<pre>
Password length(4..99):12
Passwords required(1..99):6
:EtF77s~%bok
C^Pb&NH8@?u6
Line 3,207 ⟶ 4,100:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">#!/usr/bin/pil
 
# Default seed
Line 3,270 ⟶ 4,163:
(rot '(*UppChars *Others *Digits *LowChars))) ) ) ) ) ) ) )
 
(bye)</langsyntaxhighlight>
Test:
<pre>$ genpw --help
Line 3,291 ⟶ 4,184:
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
function New-RandomPassword
{
Line 3,411 ⟶ 4,304:
}
}
</syntaxhighlight>
</lang>
<syntaxhighlight lang="powershell">
<lang PowerShell>
New-RandomPassword -Length 12 -Count 4 -ExcludeSimilar
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,423 ⟶ 4,316:
</pre>
Make it Unix-like:
<syntaxhighlight lang="powershell">
<lang PowerShell>
Set-Alias -Name nrp -Value New-RandomPassword -Description "Generates one or more passwords"
 
nrp -l 12 -n 4 -x
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 3,438 ⟶ 4,331:
=={{header|Prolog}}==
{{works with|SWI-Prolog|7.6.4 or higher}}
<langsyntaxhighlight Prologlang="prolog">:- set_prolog_flag(double_quotes, chars).
:- initialization(main, main).
 
Line 3,495 ⟶ 4,388:
pword_char( upper, C ) :- member( C, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ).
pword_char( digits, C ) :- member( C, "0123456789" ).
pword_char( special, C ) :- member( C, "!\"#$%&'()*+,-./:;<=>?@[]^_{|}~" ).</langsyntaxhighlight>
{{out}}
Showing help
Line 3,531 ⟶ 4,424:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">EnableExplicit
 
Procedure.b CheckPW(pw.s)
Line 3,652 ⟶ 4,545:
~"Blabla blabla bla blablabla."
EndOfHelp:
EndDataSection</langsyntaxhighlight>
{{out}}
<pre>Length of the password (n>=4): 10
Line 3,673 ⟶ 4,566:
=={{header|Python}}==
 
<langsyntaxhighlight lang="python">import random
 
lowercase = 'abcdefghijklmnopqrstuvwxyz' # same as string.ascii_lowercase
Line 3,707 ⟶ 4,600:
for i in range(qty):
print(new_password(length, readable))
</syntaxhighlight>
</lang>
{{output}}
<pre>>>> password_generator(14, 4)
Line 3,721 ⟶ 4,614:
 
=={{header|R}}==
<syntaxhighlight lang="r">
<lang r>
passwords <- function(nl = 8, npw = 1, help = FALSE) {
if (help) return("gives npw passwords with nl characters each")
Line 3,746 ⟶ 4,639:
## Tj@T19L.q1;I*]
## 6M+{)xV?i|1UJ/
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
 
Line 3,810 ⟶ 4,703:
 
(run (len) (cnt) (seed) (readable?))
</syntaxhighlight>
</lang>
'''Sample output:'''
<pre>
Line 3,825 ⟶ 4,718:
{{works with|Rakudo|2016.05}}
 
<syntaxhighlight lang="raku" perl6line>my @chars =
set('a' .. 'z'),
set('A' .. 'Z'),
Line 3,858 ⟶ 4,751:
{$*PROGRAM-NAME} --l=14 --c=5 --x=0O\\\"\\\'1l\\\|I
END
}</langsyntaxhighlight>
'''Sample output:'''
Using defaults:
Line 3,870 ⟶ 4,763:
 
===functional===
<syntaxhighlight lang="raku" perl6line>my @char-groups =
['a' .. 'z'],
['A' .. 'Z'],
Line 3,904 ⟶ 4,797:
Password must have at least one of each: lowercase letter, uppercase letter, digit, punctuation.
END
}</langsyntaxhighlight>
'''Sample output:'''
 
Line 3,938 ⟶ 4,831:
:::* &nbsp; checking if the hexadecimal literal &nbsp; ('''yyy''') &nbsp; is valid
:::* &nbsp; checking (for instance) if all digits were excluded via the &nbsp; <b>'''xxx'''</b> &nbsp; and/or &nbsp; '''yyy''' &nbsp; option
<langsyntaxhighlight lang="rexx">/*REXX program generates a random password according to the Rosetta Code task's rules.*/
@L='abcdefghijklmnopqrstuvwxyz'; @U=@L; upper @U /*define lower-, uppercase Latin chars.*/
@#= 0123456789 /* " " string of base ten numerals.*/
Line 3,993 ⟶ 4,886:
║ The default is to use all the (normal) available characters. ║
║ yyy (same as XXX, except the chars are expressed as hexadecimal pairs).║
╚═════════════════════════════════════════════════════════════════════════════╝ */</langsyntaxhighlight>
'''output''' &nbsp; when using the inputs of: &nbsp; <tt> 10 &nbsp; 20 </tt>
<pre>
Line 4,019 ⟶ 4,912:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Password generator
 
Line 4,064 ⟶ 4,957:
end
fclose(fp)
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,071 ⟶ 4,964:
password = u8/Ah8%H
password = c4\Nc2_J
</pre>
 
=={{header|RPL}}==
{{works with|HP|48G}}
« "!" 34 CHR + "#$%&'()*+,-./:;<=>?@[]^_{|}~" + "" → chars pwd
« { 0 0 0 0 }
'''WHILE''' DUP2 ∑LIST 4 ≠ OR '''REPEAT'''
RAND 4 * CEIL
{ « RAND 25 * FLOOR 65 + CHR »
« RAND 25 * FLOOR 97 + CHR »
« RAND 10 * FLOOR →STR »
« chars RAND OVER SIZE * CEIL DUP SUB » }
OVER GET EVAL 'pwd' STO+
1 PUT
SWAP 1 - 0 MAX SWAP
'''END''' DROP2 pwd
» » '<span style="color:blue">→PWD</span>' STO ''<span style="color:grey">@ ( length → "password" )''</span>
« → length n
« '''IF''' length 4 < '''THEN'''
"Length must be at least 4" DOERR
'''ELSE'''
{ }
1 n '''FOR''' j
'''WHILE''' length <span style="color:blue">→PWD</span> DUP SIZE length > '''REPEAT''' DROP '''END'''
+
'''NEXT'''
'''END'''
» » '<span style="color:blue">PWDS</span>' STO <span style="color:grey">''@ ( length n → { "password1" .. "passwordn" } )''</span>
 
8 3 <span style="color:blue">PWDS</span>
{{out}}
<pre>
1: { "v7-c8d.B" "oVe1M$17" "R+I6vJ9j" }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight Rubylang="ruby">ARRS = [("a".."z").to_a,
("A".."Z").to_a,
("0".."9").to_a,
Line 4,090 ⟶ 5,017:
 
puts generate_pwd(8,3)
</syntaxhighlight>
</lang>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight Runbasiclang="runbasic">a$(1) = "0123456789"
a$(2) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
a$(3) = "abcdefghijklmnopqrstuvwxyz"
Line 4,132 ⟶ 5,059:
goto [main]
[exit] ' get outta here
end</langsyntaxhighlight>Output:
<pre>Generate 10 passwords with 7 characters
#1 69+;Jj8
Line 4,145 ⟶ 5,072:
#10 f0Qho:5</pre>
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
use rand::distributions::Alphanumeric;
use rand::prelude::IteratorRandom;
Line 4,219 ⟶ 5,146:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,233 ⟶ 5,160:
=={{header|Scala}}==
Using SBT to run rather than a shell script or executable jar:
<langsyntaxhighlight lang="scala">object makepwd extends App {
 
def newPassword( salt:String = "", length:Int = 13, strong:Boolean = true ) = {
Line 4,300 ⟶ 5,227:
 
if( count > 1 ) println
}</langsyntaxhighlight>
{{output}}
> sbt "run --help"
Line 4,325 ⟶ 5,252:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func string: generate (in integer: length) is func
Line 4,380 ⟶ 5,307:
end if;
end if;
end func;</langsyntaxhighlight>
 
{{out}}
Line 4,398 ⟶ 5,325:
Swift uses arc4random() to generate fast and high quality random numbers. However the usage of a user defined seed is not possible within arc4random(). To fulfill the requirements this code uses the C functions srand() and rand() that are integrated into the Swift file via an Bridging-Header.<br><br>
'''C file to generate random numbers'''
<langsyntaxhighlight Clang="c">#include <stdlib.h>
#include <time.h>
 
Line 4,412 ⟶ 5,339:
int getRand(const int upperBound){
return rand() % upperBound;
}</langsyntaxhighlight>
 
'''Bridging-Header to include C file into Swift'''
<langsyntaxhighlight Clang="c">int getRand(const int upperBound);
void initRandom(const unsigned int seed);</langsyntaxhighlight>
 
'''Swift file'''
<langsyntaxhighlight lang="swift">import Foundation
import GameplayKit // for use of inbuilt Fisher-Yates-Shuffle
 
Line 4,542 ⟶ 5,469:
for i in 1...count {
print("\(i).\t\(generatePassword(length:length,exclude:xclude))")
}</langsyntaxhighlight>
{{out}}
<pre>$ PasswordGenerator -h
Line 4,561 ⟶ 5,488:
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">
<lang vb>
Option Explicit
Sub Main()
Line 4,759 ⟶ 5,686:
End If
z = temp
End Function</langsyntaxhighlight>
{{out}}
Function Gp :
Line 4,808 ⟶ 5,735:
{{libheader|Wren-ioutil}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight pythonlang="wren">import "random" for Random
import "./ioutil" for FileUtil, File, Input
import "./fmt" for Fmt
import "os" for Process
 
Line 4,942 ⟶ 5,869:
}
 
generatePasswords.call(pwdLen, pwdNum, toConsole, toFile)</langsyntaxhighlight>
 
{{out}}
Line 4,972 ⟶ 5,899:
 
The generated passwords have been written to the file pwds.txt
</pre>
 
=={{header|XPL0}}==
{{trans|Python}}
<syntaxhighlight lang "XPL0">string 0;
 
func In(C, Str);
char C, Str;
[while Str(0) do
if C = Str(0) then return true else Str:= Str+1;
return false;
];
 
func New_password(Length, Readable);
int Length, Readable, I, C;
char Password_chars(100), Punctuation, Visually_similar;
[if Length < 4 then
[Text(0, "Password length = "); IntOut(0, Length);
Text(0, " is too short, minimum length = 4.");
return "";
];
Punctuation:= "!^"#$%&\'()*+,-./:;<=>?@[]^^_{|}~";
Visually_similar:= "Il1O05S2Z";
for I:= 0 to Length-1 do
[case Ran(4) of
0: C:= Ran(26) + ^a;
1: C:= Ran(26) + ^A;
2: C:= Ran(10) + ^0;
3: C:= Punctuation(Ran(31))
other [];
Password_chars(I):= C;
if Readable and In(C, Visually_similar) then I:= I-1;
];
Password_chars(I):= 0;
return Password_chars;
];
 
proc Password_generator(Length, Qty, Readable);
int Length, Qty, Readable, I;
for I:= 0 to Qty-1 do
[Text(0, New_password(Length, Readable)); CrLf(0)];
 
[Password_generator(14, 4, true);
Password_generator( 8, 4, false);
]</syntaxhighlight>
{{out}}
<pre>
GojA9ep6=3|U,\
U9@p|f'WH7+&TM
8=E7xvm6J9Y([q
zrknig;8Pv+(Va
37s11T68
Ir)wY0P<
54d3o]Ga
95??s]"O
</pre>
 
=={{header|zkl}}==
Put the following code into a file (such as pwdg.zkl):
<langsyntaxhighlight lang="zkl">var pwdLen=10, pwds=1, xclude="";
 
argh:=Utils.Argh(
Line 4,997 ⟶ 5,979:
pwd:=T(g1,g2,g3,g4).pump(Data,rnd); // 1 from each of these into a Data
pwd.extend(fill()).shuffle().text.println();
}</langsyntaxhighlight>
This is a command line program so output can be redirected.
{{out}}
1,150

edits