Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Reference Index > Managing User Privileges

Generating Random Text

Scroll Prev Top Next More

A random string of numbers and letters can be used as a user identifier or password. Many database applications store actual GRANT/REVOKE access names in a look-up table. The user uses their own name to retrieve a particular granted user identifier and level of access from the look-up table. In this type of application, the user identifier is never known by any user of the database. To ensure security to the data, the user identifiers stored in the look-up table are changed on a regular basis. This command file uses the #TIME and #DATE system variables and various date and time functions to create a random character string of numbers and letters. The password look-up table is updated with the random string created by the program.

 

SET VAR vRandomText TEXT = NULL

 

-- The source variable, make sure there are

-- no spaces in the string.

SET VAR vKey TEXT = +

 ('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,0,1,2,3,4,5,6,7,8,9')

 

SET VAR vTime TIME = (.#TIME)

SET VAR vChar1 INTEGER = (ISEC(.vTime))

 

-- Require the first character to be a letter.

WHILE vChar1 > 26 THEN

 SET VAR vChar1 = (.vChar1 - 26)

ENDWHILE

 

-- Set character 2 to the minutes portion of the time.

-- This section needs a test for greater than 36,

-- if the value is out of range, the result is null

SET VAR vChar2 INTEGER = (IMIN(.vTime))

 

-- Set character 3 to the minutes divided by 6,

-- this will never be a number greater than 10.

SET VAR vChar3 INTEGER = (IMIN(.vTime)/6)

 

-- Set character 4 to the day portion of the date.

SET VAR vChar4 INTEGER = (IDAY(.#DATE))

 

-- Character 4 can never be greater than 36.

SET VAR vChar4 = (.vChar4 + 5)

IF vChar4 > 36 THEN

 SET VAR vChar4 = (vChar4 - 36)

ENDIF

 

-- Set character 5 to the number of the day

-- of the week, this is a number between 1 and 7,

-- and then multiply by the value of character 3.

-- The maximum value for this number is 70.

SET VAR vChar5 INTEGER = (IDWK(.#DATE))

SET VAR vChar5 = (.vChar5 * .vChar3)

 

-- Make sure this number is less than 36.

IF vChar5 > 36 THEN

 SET VAR ch5 = (.vChar5 - 36)

ENDIF

 

-- Set character 6 to the month portion of the date

-- and then add the value of character 5

-- (maximum for 5 is 34, plus 12 = 46).

SET VAR vChar6 INTEGER = (IMON(.#DATE))

SET VAR vChar6 = (.vChar6 + .vChar5)

IF vChar6 > 36 THEN

 SET VAR vChar6 = (.vChar6 - 36)

ENDIF

 

-- Set character 7 to the Julian date of the date,

-- then get the third and fourth characters from it.

-- This will be a number between 0 and 36.

-- Need to test for 0, when 0 this character is null.

SET VAR vChar7 INTEGER = (JDATE(.#DATE))

SET VAR vChar7 TEXT

SET VAR vChar7 = (SGET(.vChar7,2,3))

IF vChar7 = '00' THEN

 SET VAR vChar7 = (SGET(.vChar7,2,4))

ENDIF

SET VAR vChar7 INTEGER

 

-- The hour portion of the time plus 12, is a number

-- between 12 and 24.

SET VAR vChar8 INTEGER = ((IHR(.vTime))+12)

 

-- Add all the previous character values together

-- and divide by 8, the average of all the previous

-- characters

SET VAR vChar9 INTEGER = +

 ((.vChar1+.vChar2+.vChar3+.vChar4+.vChar5+.vChar6+.vChar7+.vChar8)/8)

 

-- Get the actual characters from the source variable.

SET VAR vRandomText = +

(SSUB(.vKey,.vChar1) + SSUB(.vKey,.vChar2) + +

SSUB(.vKey,.vChar3) + SSUB(.vKey,.vChar4) + +

SSUB(.vKey,.vChar5) + SSUB(.vKey,.vChar6) + +

SSUB(.vKey,.vChar7) + SSUB(.vKey,.vChar8) + +

SSUB(.vKey,.vChar9))

 

CLEAR VAR vChar%, vKey, vTime

RETURN