LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Password mask issue

I am trying to create a login panel for test purposes, and it opens
whenever the Test GUI is first opened and it requests a valid username
and password entry before opening the test GUI. I am using the
pwctrl.fp and the PasswordCtrl_ConvertFromString command to mask the
password string in the password entry text box, but the password is
not getting masked with the "*" character as I was expecting. I tried
following the password example project, but with no success. I have
attached the code snippets to see if anyone can point out the error in
my ways. Thanks for any help.

/
********************************************************************************
* Login() *
* Purpose: This function opens a login panel and waits for the login
input. *

********************************************************************************/
int Login()
{
int iMaxPasswordLength = 25;
char maskChar[2] = "*";

giLoginPanel = LoadPanel(0, "mainTestGui.uir", LOGIN);

/* Convert a string control into a password control! */
giPasswordCtrlID = PasswordCtrl_ConvertFromString (giLoginPanel,
LOGIN_PASSWORD);

PasswordCtrl_SetAttribute (giLoginPanel, giPasswordCtrlID,
ATTR_PASSWORD_MASK_CHARACTER, maskChar);
PasswordCtrl_SetAttribute (giLoginPanel, giPasswordCtrlID,
ATTR_PASSWORD_MAX_LENGTH, iMaxPasswordLength);

ProcessDrawEvents();

// Install callback functions
InstallCtrlCallback (giLoginPanel, LOGIN_USERNAME, Clb_LoginData,
0);
InstallCtrlCallback (giLoginPanel, LOGIN_PASSWORD, Clb_LoginData,
0);
InstallCtrlCallback (giLoginPanel, LOGIN_OK, Clb_LoginData, 0);

SetActiveCtrl (giLoginPanel, LOGIN_USERNAME);

// open the login data panel
InstallPopup (giLoginPanel);

// Start processing panel events.
giRunLogin = RunUserInterface();

// Discard panel after it has been closed.
DiscardPanel(giLoginPanel);

return 0;
}

/*
* Clb_LoginData()
*
* Purpose:
* This callback function handles login entry inputs.
*/
int CVICALLBACK Clb_LoginData(int panel, int control, int event, void
*callbackData, int eventData1, int eventData2)
{
// Local variables
int iValidData = 0;
char cUserName[50] = "\0";
char cPassWord[50] = "\0";
char cUN1[50] = "\0";
char cPW1[50] = "\0";

switch (event)
{
case EVENT_COMMIT:

switch (control)
{
case LOGIN_OK:

// get the entered login information
GetCtrlVal (giLoginPanel, LOGIN_USERNAME, cUserName);
GetCtrlVal (giLoginPanel, LOGIN_PASSWORD, cPassWord);

// get the correct login information from the ini file
Ini_GetStringIntoBuffer(gIniText,"Login","UN1", cUN1, sizeof
(cUN1));
Ini_GetStringIntoBuffer(gIniText,"Login","PW1", cPW1, sizeof
(cPW1));

// compare the login that was entered to the login information
from the ini file
if (strcmp(cUserName, cUN1) == 0 && strcmp(cPassWord, cPW1) == 0)
iValidData = 1;
// if the data compares, then close the login panel and continue
to the test
if (iValidData)
// Close scan UUT data panel
QuitUserInterface (giRunLogin);
else
{ // else clear out the information and enter it again
SetCtrlVal (giLoginPanel, LOGIN_USERNAME, "");
SetCtrlVal (giLoginPanel, LOGIN_PASSWORD, "");
SetActiveCtrl (giLoginPanel, LOGIN_USERNAME);
SetCtrlAttribute (giLoginPanel, LOGIN_OK, ATTR_DIMMED, 1);
}
break;

case LOGIN_USERNAME:

// Advance to the next field if the username length is greater
than 0.
GetCtrlVal (giLoginPanel, LOGIN_USERNAME, cUserName);

if(strlen(cUserName))
{
// Select CID SN field as active
SetActiveCtrl (giLoginPanel, LOGIN_PASSWORD);
}
else
{
SetCtrlVal (giLoginPanel, LOGIN_USERNAME, "");
SetCtrlAttribute (giLoginPanel, LOGIN_OK, ATTR_DIMMED, 1);
SetActiveCtrl (giLoginPanel, L
0 Kudos
Message 1 of 5
(3,868 Views)

I use the password instrument in almost every application I write, and never saw such a problem. I use a more simplistic approach, though, which you could try to check your environment:

 

1. Since username and password max lenght is not subject to change during program life, I set the corresponding max lenght in the string controls of the login panel

2. I don't try to automatically advance from one field to the next: let the user use the mouse or TAB key instead

3. To use the below discussed approach, all controls on the login panel MUST be set as "Normal" with the exception of "Ok" and "Cancel" buttons

 

This is the code for handling all login procedure (e.g. in a callback for starting a test):

 

    int        ctrl, tmpH = 0;
    char    msg[512];

 

    // Load the panel and customize password string control   

    tmpH = LoadPanel (0, UIR, pswd);
    PasswordCtrl_ConvertFromString (tmpH, pswd_pswd);

    // Install the panel as modal popup

    InstallPopup (tmpH);

    // Handle user events

    while (TRUE) {
        GetUserEvent (1, 0, &ctrl);            // Wait for next commit event
        if (ctrl == pswd_quit)                     // User pressed "Cancel" button

           break;
        else if (ctrl == pswd_ok) {

            // ** Add code to check username **

           errChk (PasswordCtrl_GetAttribute (tmpH, pswd_pswd, ATTR_PASSWORD_VAL, msg));
            if (strcmp (password, msg))
                MessagePopup ("Warning!", "Incorrect password entered!");
            else
                break;
        }
    }

   // Remove panel

   DiscardPanel (tmpH); tmpH = 0;
    if (ctrl == pswd_quit) goto Error;
 

    // The rest of your code here

 

Error:

    // Finalization of the routine: discard dynamic memory, deallocate resources and so on

    return 0;


As a last note, avoid calling RunUserInterface and QuitUserInterface more than once i your program: the first one should be called at the beginning of the program to start processing events, while the second only when you want to quit the application. All processing of panels and events can be managed without need to further call of these instructions, which could ingenerate abnormal application behaviour.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(3,860 Views)
On Jan 16, 4:18 pm, mehmmr...@yahoo.com wrote:
> I am trying to create a login panel for test purposes, and it opens
> whenever the Test GUI is first opened and it requests a valid username
> and password entry before opening the test GUI. I am using the
> pwctrl.fp and the PasswordCtrl_ConvertFromString command to mask the
> password string in the password entry text box, but the password is
> not getting masked with the "*" character as I was expecting. I tried
> following the password example project, but with no success. I have
> attached the code snippets to see if anyone can point out the error in
> my ways. Thanks for any help.
>
> /
> ********************************************************************************
>  *  Login()                                                                                                                     *
>  *  Purpose: This function opens a login panel and waits for the login
> input.  *
>
> ********************************************************************************/
> int Login()
> {
>         int iMaxPasswordLength = 25;
>         char maskChar[2] = "*";
>
>     giLoginPanel = LoadPanel(0, "mainTestGui.uir", LOGIN);
>
>     /* Convert a string control into a password control! */
>     giPasswordCtrlID = PasswordCtrl_ConvertFromString (giLoginPanel,
> LOGIN_PASSWORD);
>
>     PasswordCtrl_SetAttribute (giLoginPanel, giPasswordCtrlID,
> ATTR_PASSWORD_MASK_CHARACTER, maskChar);
>     PasswordCtrl_SetAttribute (giLoginPanel, giPasswordCtrlID,
> ATTR_PASSWORD_MAX_LENGTH, iMaxPasswordLength);
>
>         ProcessDrawEvents();
>
>         //      Install callback functions
>         InstallCtrlCallback (giLoginPanel, LOGIN_USERNAME, Clb_LoginData,
> 0);
>         InstallCtrlCallback (giLoginPanel, LOGIN_PASSWORD, Clb_LoginData,
> 0);
>         InstallCtrlCallback (giLoginPanel, LOGIN_OK,       Clb_LoginData, 0);
>
>         SetActiveCtrl (giLoginPanel, LOGIN_USERNAME);
>
>                 // open the login data panel
>         InstallPopup (giLoginPanel);
>
>         //      Start processing panel events.
>     giRunLogin = RunUserInterface();
>
>         //      Discard panel after it has been closed.
>         DiscardPanel(giLoginPanel);
>
>         return 0;
>
> }
>
> /*
>  *      Clb_LoginData()
>  *
>  *      Purpose:
>  *              This callback function handles login entry inputs.
>  */
> int  CVICALLBACK Clb_LoginData(int panel, int control, int event, void
> *callbackData, int eventData1, int eventData2)
> {
>         //      Local variables
>         int             iValidData = 0;
>         char    cUserName[50] = "\0";
>         char    cPassWord[50] = "\0";
>         char    cUN1[50] = "\0";
>         char    cPW1[50] = "\0";
>
>     switch (event)
>     {
>                 case EVENT_COMMIT:
>
>                         switch (control)
>                         {
>                                 case LOGIN_OK:
>
>                                 // get the entered login information
>                                 GetCtrlVal (giLoginPanel, LOGIN_USERNAME, cUserName);
>                                 GetCtrlVal (giLoginPanel, LOGIN_PASSWORD, cPassWord);
>
>                                         // get the correct login information from the ini file
>                                         Ini_GetStringIntoBuffer(gIniText,"Login","UN1", cUN1, sizeof
> (cUN1));
>                                         Ini_GetStringIntoBuffer(gIniText,"Login","PW1", cPW1, sizeof
> (cPW1));
>
>                                         // compare the login that was entered to the login information
> from the ini file
>                                         if (strcmp(cUserName, cUN1) == 0 && strcmp(cPassWord, cPW1) == 0)
>                                                 iValidData = 1;
>                                         // if the data compares, then close the login panel an
0 Kudos
Message 3 of 5
(3,819 Views)

Hello,

 

Does your repost indicate that the problem persists?

0 Kudos
Message 4 of 5
(3,787 Views)

Hello,

 

I faced the problem you are facing over one year ago. To solve the problem of  "... password is not getting masked with the "*" character ..."  I did a lot of experimentation. I finally got it to work when I changed the maskChar to  '*\0'.  So, in your case I would suggest you use the statement below:

 

PasswordCtrl_SetAttribute (giLoginPanel, giPasswordCtrlID,
ATTR_PASSWORD_MASK_CHARACTER, '*\0');                      // maskChar is replaced by  '*\0'. Note that it is one quote (not double quotes).

Asterisks (*) would now show up as your masking character.

(NOTE:  When you run your application, you would get the warning  "Excess characters in multibyte character literal ignored". Ignore this warning. Your application would run fine).

Let me know how things go.

 

Robert Mensah

0 Kudos
Message 5 of 5
(3,775 Views)