816.TXT ===================================================================== Generating Random Text ===================================================================== PRODUCT: R:BASE VERSION: All ===================================================================== CATALOG: General Information AREA : Data Manipulation ===================================================================== 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. *(randtext.cmd) SET VAR vName 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 ch1 INTEGER = (ISEC(.vTime)) -- Require the first character to be a letter. WHILE ch1 > 26 THEN SET VAR ch1 = (.ch1 - 26) ENDWH -- 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 ch2 INTEGER = (IMIN(.vTime)) -- Set character 3 to the minutes divided by 6, -- this will never be a number greater than 10. SET VAR ch3 INTEGER = (IMIN(.vTime)/6) -- Set character 4 to the day portion of the date. SET VAR ch4 INTEGER = (IDAY(.#DATE)) -- Character 4 can never be greater than 36. SET VAR ch4 = (.ch4 + 5) --IF ch4 > 36 THEN -- SET VAR ch4 = (ch4 - 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 ch5 INTEGER = (IDWK(.#DATE)) SET VAR ch5 = (.ch5 * .ch3) -- Make sure this number is less than 36. IF ch5 > 36 THEN SET VAR ch5 = (.ch5 - 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 ch6 INTEGER = (IMON(.#DATE)) SET VAR ch6 = (.ch6 + .ch5) IF ch6 > 36 THEN SET VAR ch6 = (.ch6 - 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 ch7 INTEGER = (JDATE(.#DATE)) SET VAR ch7 TEXT SET VAR ch7 = (SGET(.ch7,2,3)) IF ch7 = '00' THEN SET VAR ch7 = (SGET(.ch7,2,4)) ENDIF SET VAR ch7 INTEGER -- The hour portion of the time plus 12, is a number -- between 12 and 24. SET VAR ch8 INTEGER = ((IHR(.vTime))+12) -- Add all the previous character values together -- and divide by 8, the average of all the previous -- characters SET VAR ch9 INTEGER = + ((.ch1+.ch2+.ch3+.ch4+.ch5+.ch6+.ch7+.ch8)/8) -- Get the actual characters from the source variable. SET VAR vName2 = + (SSUB(.vKey,.ch1) + SSUB(.vKey,.ch2) + + SSUB(.vKey,.ch3) + SSUB(.vKey,.ch4) + + SSUB(.vKey,.ch5) + SSUB(.vKey,.ch6) + + SSUB(.vKey,.ch7) + SSUB(.vKey,.ch8) + + SSUB(.vKey,.ch9)) CLEAR VAR ch%, vKey, vTime RETURN