user login error

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
rajeshwar333
Posts: 10
Joined: July 11th, 2020, 2:02 pm

user login error

Post by rajeshwar333 »

Dear Friends, while setting-up login credentials, I'm getting error. Following is the code used for loading external file with login details
PROC USER_NAME
post proc
if loadcase (LOGINS_DICT,USERNAME)=0 then
errmsg ("Invalid Login credentials");
ENDIF;
savesetting("login",maketext("%v", USER_NAME));

Also, username should get save for ever for that device based on "Savesetting". However, it is asking user login details for every entry.

Note: I have taken "Mobile data collecting using CSPRO, page 66 as reference for code"
aaronw
Posts: 564
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: user login error

Post by aaronw »

There are two parts to your code:
  • Loading the case into memory
  • Saving the code for retrieval at another time
For part one you'll use the user entered username to load the staff code. Your error could be that the variable name is USER_NAME, but your loadcase function is taking USERNAME (no underscore) as an argument.

For part two it is true that savesettings will save the value of USER_NAME on the local device. However, that is all it does. You'll still be prompted to enter the user credentials. To automate this you'll use loadsetting to retrieve the stored username and then prefill it.
preproc

string
login_username = loadsetting("login");

if login_username <> "" then
    // prefill and advance without user input
   
USERNAME_NAME = login_username;
   
noinput;
endif;
Finally, I assume the point of the loadcase was to get access to the staff code. I might also consider storing/prefilling it.
rajeshwar333
Posts: 10
Joined: July 11th, 2020, 2:02 pm

Re: user login error

Post by rajeshwar333 »

Thank you for the reply.

With your inputs and others info, i have done some editing to the code. and finally landed two 2 errors

1. Variable(s) length do not agree with dictionary ID length
2. PostProc clause expected.

For sometime the only username condition worked and when tried to add password condition also, both got distrusted.
I have checked several times on variable length between variable and dictionary. But could not identify the problem.

My requirement is: using external file credentials, create condition for user login.

Attached all files for review and requesting team to help me out.
Attachments
CAPI.rar
(66.85 KiB) Downloaded 157 times
aaronw
Posts: 564
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: user login error

Post by aaronw »

The issue is that loadcase expects the entire key. If you make this change in both locations the error goes away.
USERNAME = $;
if loadcase(LOGINS_DICT, USERNAME, PASSWORD)=0 then
    errmsg
("Invalid user name");
   
reenter;
endif;
I would make the password id a regular field. Then I would validate the username based on the result of the loadcase. If the loadcase fails then the username is not in the lookup file and is not valid. On the next field you can validate the password based on what is in memory from the loadcase.
Post Reply