LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Ctr C and Ctrl V in password control example

Hi..!

From the enclosed example, if use Ctrl c and Ctrl V,
I mean when i copy and paste the password, then getCtrl
attribut function dose't get the entered string. What is the reason..? How can i eliminate it..?

Thanx and Regards,
Venki
0 Kudos
Message 1 of 5
(4,461 Views)
The reason why pasting a text doesn't update the password value resides inside the password control itself. Surely you have noticed that the text pasted into the string is not masked with asterisks; this fact and the behaviour you noted depend on the same reason: the passowrd control does not integrates full functionality of normal input text fields.
 
If you deep into the instrument source (Instrument menu >> Edit function >> Attach and edit source on the password control instrument)) you can look into the PasswordCtrl_Callback () function, which is chained to the string field when you use PasswordCtrl_ConvertFromString. Inside this function a couple of events are swallowed (discarded) so that no user input is done on these events (an example ot these are arrow keys pressing events). The VAL_CHANGED event which is fired when pasting some text inside the control is neither specifically discarded nor specifically treated inside the function so that internal image of the password entered is not updated (and text is not masked).
To modify this behaviour you must modify the password control instrument to intercept VAL_CHANGED event and swallow it (so that no update is visible on the password - simplest solution) or manage it reading the entire content of the field and updating internal copy of the password for non-asterisk characters (more complex solution - moreover: what if the pasted text is or contains an asterisk?).
 
I noticed you are using an old version of CVI (5.0.1): upgrading the system does not improve this particular aspect of the password control, which has remained identical at least up to version 7.1.1 (but indeed guarantees you a more friendly and complete development system Smiley Wink )


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?
Message 2 of 5
(4,447 Views)
Hi thank you verymuch for the response..!

I am using CVI 7.1.1.
Probably I have done it..

char pw[11];
char *string;
int length;

switch (event)
{
case EVENT_COMMIT:


// The user commited the password, what did they type?
PasswordCtrl_GetAttribute (hMainPanel, hPWControl, ATTR_PASSWORD_VAL, pw);

GetCtrlValStringLength(panel, MAINPNL_PWD, &length);
string = malloc(sizeof(char) * (length + 1));
GetCtrlVal(hMainPanel, MAINPNL_PWD, string);

if(strlen(pw)==0){
printf("%s", string);
MessagePopup("PASSWORD",string);
}

free(string);

MessagePopup ("PASSWORD", pw);
break;
}
0 Kudos
Message 3 of 5
(4,442 Views)

Hi Monky, in you approach you are retrieving first the value of the password from the instrument (pw) next the content of the string control (string): I suppose you will be trying to compare each of them against a stored password to ceck if the user has correctly typed the password. As far as I can understand, this system will work if and only the user either directly types the entire password or paste in the field the entire password. If the user types some characters and completes the password pasting the rest of it in the field none of the two values retrieved will be right: the one get from the instrument will include only characters directly typed, the one retrieve from the control will include asterisks and some other plain characters.

In my opinion you have to modify intrument surce to manage some way the paste event.

As per software version, I looked into the .PRJ file you attached and it says version 5.0.1, but maybe it is an old version of the project file...



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?
Message 4 of 5
(4,427 Views)
In bothway it helps..thax again

int CVICALLBACK PasswordCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char pw[100];
char *string;
int length;

switch (event)
{
case EVENT_COMMIT:


// The user commited the password, what did they type?
PasswordCtrl_GetAttribute (hMainPanel, hPWControl, ATTR_PASSWORD_VAL, pw);

GetCtrlValStringLength(panel, MAINPNL_PWD, &length);
string = malloc(sizeof(char) * (length + 1));
GetCtrlVal(hMainPanel, MAINPNL_PWD, string);

strcpy(pw,string);

printf("%s",pw);

free(string);

//MessagePopup ("PASSWORD", pw);

break;
}
return 0;
}
0 Kudos
Message 5 of 5
(4,402 Views)