Sample code for 30+ languages & platforms
PowerBuilder

Generating Random Password

See more PRNG Examples

Demonstrates how to generate random passwords.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Fortuna
integer li_BDigit
integer li_BUpperAndLower
string ls_OtherChars
string ls_ExcludeChars
integer i

li_Success = 0

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

li_Success = 0

loo_Fortuna = create oleobject
li_rc = loo_Fortuna.ConnectToNewObject("Chilkat.Prng")
if li_rc < 0 then
    destroy loo_Fortuna
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Set this equal to 1 if the generated password must include at least one digit (0-9)
li_BDigit = 1

// Set this equal to 1 if the generated password must include both uppercase and lowercase chars.
li_BUpperAndLower = 1

// The generated password must contain one of the following non-alphanumeric chars.
ls_OtherChars = "@#$%*"

// Exclude chars that appear similar to others:
ls_ExcludeChars = "iIlLoO0"

// Generate 8-character passwords:

for i = 1 to 10
    Write-Debug loo_Fortuna.RandomPassword(8,li_BDigit,li_BUpperAndLower,ls_OtherChars,ls_ExcludeChars)
next


destroy loo_Fortuna