Skip to content

Instantly share code, notes, and snippets.

@NielsLiisberg
Created October 28, 2021 12:56
Show Gist options
  • Save NielsLiisberg/0dc10d665b94fe427f960b1b6537e933 to your computer and use it in GitHub Desktop.
Save NielsLiisberg/0dc10d665b94fe427f960b1b6537e933 to your computer and use it in GitHub Desktop.
SQL logon - check user profile and password
-- Check the user profile and password
-- This also showcase how to integrate the C code directly into your UDTF
-- You need my IFS_WRITE UDTF found elsewhere at my gist
--
-- Simply paste this gist into ACS SQL and step through the example.
--
-- It is a cool example how far you can go with SQL: Have fun -
-- (C) Niels Liisberg 2021
--
-- This gist is distributed on an "as is" basis, without warranties
-- or conditions of any kind, either express or implied.
----------------------------------------------------------------------------------------------
call qusrsys.ifs_write('/tmp/main.c' , '
{
#include "QSYSINC/H/QSYGETPH"
QSYGETPH (
MAIN.USR_ID
, MAIN.USR_PASSWORD
, MAIN.HAND
, MAIN.ERR
, MAIN.USR_PASSWORD_LEN
, MAIN.USR_CCSID
);
}
');
create or replace function qusrsys.logon (
user_id char(10),
user_password varchar(128) ccsid 1208
)
returns varchar (256)
set option output=*print, commit=*none, dbgview = *source --list
main:begin
declare usr_id char(10);
declare usr_password_len int;
declare usr_password char(128) ccsid 1208;
declare usr_ccsid int;
declare err char(256);
declare hand char(12);
set err = x'000000ff00000000';
set usr_id = user_id;
set usr_password_len = length(user_password);
set usr_password = user_password;
set usr_ccsid = 1208;
include '/tmp/main.c';
return substring( err , 9);
end;
-- unit test
values (
qusrsys.logon ('DEMO' , 'demo2')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment