19. Password strength-related analysis
*password.txt *stores some user names and corresponding passwords for a system. It stores 5 items in each row. Odd number rows have user names and even number rows contain passwords:
We want to convert it to to a table sequence made up of 4 fields – ID, USER, PASSWORD and LEVEL, and analyze password strength on LEVEL field. The highest strength level is 5. Here are 5 descriptions, and add 1 to the strength when a description is found true: (1) Contain lowercase letters; (2) Contain uppercase letters; (3) Contain numbers or decimal point; (4) Contain other characters; and (5) Length of the password is at least 8 characters. The task is to list users whose password strength is less than 3.
Expected result:
SPL code:
A | B | C | D | |
---|---|---|---|---|
1 | password.txt | =file(A1).read() | ||
2 | =B1.split@bn(“\t”) | |||
3 | =A2.step(2,1).conj() | =A2.step(2,2).conj() | ||
4 | =create(ID,USER,PASSWORD,LEVEL) | >A4.modify(0:A3,#:ID,~:USER,B3(#):PASSWORD) | ||
5 | for A4 | =A5.PASSWORD.split() | =0 | =0 |
6 | =0 | =0 | =if(B5.len()>=8,1,0) | |
7 | for B5 | if islower(B7) | >C5=1 | |
8 | else if isupper(B7) | >D5=1 | ||
9 | else if isdigit(B7) || B7==“.” | >B6=1 | ||
10 | else | >C6=1 | ||
11 | >A5.LEVEL=C5+D5+B6+C6+D6 | |||
12 | =A4.select(LEVEL<3) |
B1 reads data from the file as a string. A2 uses s.split() function to split the string. @n option performs the splitting line by line and then splits each line by the delimiter specified in the parameter. As the password the file stores contains special characters, @b option is needed to handle the possbile parentheses or quotations to make sure the splitting is correctly executed. Below is A2’s result:
Each line of the file is split by tab \t as a sequence. A3 and B3 use A.step()function to get username and password from every other line and execute A.conj() function to respectively generate a sequence of usernames and passwords.
A4 creates the result table sequence. In B4, T.modify() function fills data of both A3 and B3 in A4’s table sequence. We can also use A.new()function to directly generate a new table sequence, and call T.insert() to insert new records into it. A5 performs the loop operation to judge each user’s password strength. Lines from 5 to 11 judges the length of each user’s password and type of each of the password’s characters to find whether the password meets the descriptions or not. B11 computes the password strength and assigns it to LEVEL field. Execute the loop and A4 gets the following result set:
Then A12 selects records where the password strength level is less than 3.
20. Handling big, multiline data using the cross-cellset cursor
Contents and Exercise Data
SPL Official Website 👉 https://www.esproc.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.esproc.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/2bkGwqTj
Youtube 👉 https://www.youtube.com/@esProc_SPL
Chinese version