ABAP Function Module For Random Password Generator
ABAP Function Module For Random Password Generator
2005 SAP AG
Applies To:
SAP NetWeaver Web AS, BSP
Summary
This function module (FM) will generate a random password with a length specified via the import parameter. The FM will return a random password containing case sensitive (alpha)-numeric characters. For detailed information, see my weblog at: https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2584. By: Eddy De Clercq Company: Katholieke Universiteit Leuven Date: 26 October 2005
Code
FUNCTION z_generate_pwd. *"---------------------------------------------------------------------*"*"Local interface: *" *" *" *" IMPORTING REFERENCE(CHARS) TYPE EXPORTING REFERENCE(PWD) TYPE STRING I
*"---------------------------------------------------------------------DATA: a_sign TYPE x, xpwd TYPE xstring, conv TYPE REF TO cl_abap_conv_in_ce, prnga TYPE REF TO cl_abap_random_int, prngb TYPE REF TO cl_abap_random_int, prngc TYPE REF TO cl_abap_random_int, prngd TYPE REF TO cl_abap_random_int, seed TYPE i, random TYPE i.
seed = cl_abap_random=>seed( ). prnga = cl_abap_random_int=>create( seed = seed min = 1 max = 3 ). seed = cl_abap_random=>seed( ). prngb = cl_abap_random_int=>create( seed = seed min = 48 max = 57 ). seed = cl_abap_random=>seed( ). prngc = cl_abap_random_int=>create( seed = seed min = 65 max = 90 ). seed = cl_abap_random=>seed( ). prngd = cl_abap_random_int=>create( seed = seed min = 97 max = 122 ). 2005 SAP AG The SAP Developer Network: http://sdn.sap.com 1
DO chars TIMES. random = prnga->get_next( ). CASE random. WHEN 1. a_sign = prngb->get_next( ). WHEN 2. a_sign = prngc->get_next( ). WHEN 3. a_sign = prngd->get_next( ). ENDCASE. CONCATENATE xpwd a_sign INTO xpwd IN BYTE MODE. ENDDO. conv = cl_abap_conv_in_ce=>create( input = xpwd ). conv->read( IMPORTING data = pwd ).
ENDFUNCTION.
Author Bio
Eddy De Clercq has 20 years experience in computing. He currently works at the Katholieke Universiteit Leuven, the oldest university of the Low Countries and the largest Flemish university. Eddy makes part of the E-university team that creates mostly self services (web) applications.
2005 SAP AG