RandomPassword ( )

Function stats

Average user rating
5.0000
307
366
9999
Support
FileMaker 7.0 +
Date posted
26 March 2014
Last updated
16 April 2014
Version
Recursive function
Yes

Author Info
 HOnza

1 functions

Average Rating 5.0

author_avatar



 

Function overview

Prototype

RandomPassword  ( passlen )


Parameters

passlen  Length of the password to generate


Description

Tags:  security   Recursive   Random   password  

This custom functions generated a string random password of the desired length. Some easy-to-mistake characters are intentionally omitted.

Examples

Sample input

RandomPassword(15)


Sample output

dN*6@ZBfMr+E7Bj

 

Function code

Case(
not passlen; Middle("!@#$%&*+?"; Round(Random * 8; 0) + 1; 1);
passlen = 1; Middle("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789"; Round(Random * 56; 0) + 1; 1);
passlen ≤ 6; RandomPassword(1) & RandomPassword(passlen - 1);
passlen ≤ 8; Replace(RandomPassword(passlen - 1); Round(Random * (passlen - 3); 0) + 2; 0; RandomPassword(0));
RandomPassword(8) & RandomPassword(passlen - 8)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/366

    Prototype: RandomPassword( passlen )
    Function Author: HOnza (http://www.fmfunctions.com/mid/307)
    Last updated: 16 April 2014
    Version: 2.0

*/
// ===================================

 

Comments

Fabrice
16 April 2014



Hi HOnza,

looks like an empty parameter causes an infinite loop.
This can be fixed by replacing
passlen=0; Middle("!@#$%&*+?"; Round(Random * 8; 0) + 1; 1);

with
not passlen; Middle("!@#$%&*+?"; Round(Random * 8; 0) + 1; 1);
 Bug report
HOnza
16 April 2014



Good point, Fabrice, thanks!
  General comment
metalox
24 April 2014



Works a treat - very useful, thanks!

I added a Let clause in the beginning for readability and robustness - maybe you find it useful.

Let( [
    ~X = "!@#$%&*+?";
    ~LenX = Length ( ~X ) -1;
    ~Y= "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789";
    ~LenY = Length ( ~Y ) -1
] ;
Case(
    not passlen ; Middle ( ~X ; Round ( Random * ~LenX ; 0 ) + 1 ; 1 );
    passlen = 1 ; Middle ( ~Y; Round(Random * ~LenY ; 0 ) + 1 ; 1 );
    passlen ≤ 6 ; RandomPassword ( 1 ) & RandomPassword ( passlen - 1 );
    passlen ≤ 8 ; Replace ( RandomPassword ( passlen - 1 ) ; Round(Random * ( passlen - 3 ) ; 0 ) + 2 ; 0 ; RandomPassword ( 0 ) );
    RandomPassword(8) & RandomPassword(passlen - 8)

    ) // close Case
) // close Let
(Edited by metalox on 24/04/14 )
  General comment

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (27)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (13)
Filter  (12)
Layout Objects  (11)
Design  (10)
Array  (8)