Check Whether an Input User Has a Match in a CSV File
Problem description & analysis
The CSV file userlogin.csv records user login information, as shown below:
Ccustomer1lastname,9774ASU,Customer
Ccustomer2lastname,6979ASU,Customer
mman,4234ASU,Manager
The three columns are customer names, passwords and role. We are trying to check whether an input parameter (a username, a password or a role) matches one of the records in the CSV file (case-insensitive). Return true if there are any match and login successfully; return false if there is no matching record and login fails.
Solution
Write the following script p1.dfx in esProc:
A |
|
1 |
=file("userlogin.csv").read@n() |
2 |
=lower([username,password,role].concat@c()) |
3 |
return A1.select@1(lower(~)==A2)!=null |
Explanation:
Set three cellset parameters:
1. Parameter name: username
2. Parameter name: password
3. Parameter name: role
A1 Read in the CSV file as a sequence of strings.
A2 Define a sequence of the three defined parameters, transform them into strings by comma, and convert it into lowercase.
A3 Get the eligible members (strings matching A2 after conversion into lowercase) from A1’s sequence. If the current member (string) has a match, return true, otherwise return false.
Find how to integrate the script code into a Java program in How to Call an SPL Script in Java.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL