LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Password Popup?

I'm after a password popup control that works exactly like PromptPopup() but hashes out the text so it can't be seen.
I have tried using the PasswordCtrl_Create & PasswordCtrl_ConvertFromString functions but they seem to only work on a panel, but I don't want a panel I want a popup box so my code does not simply continue.
i.e. I want my code to stop at the point I call up the password box, wait for the password to be entered, and then return a string so my code can decide what action to take.
 
Is there such a beast?
 
Thanks
Dave 🙂
0 Kudos
Message 1 of 22
(6,502 Views)

Hi Dave.

What you need to do is:

  • create a panel with a string control and OK and Cancel buttons
  • write a callback for each button
  • in your code, call PasswordCtrl_ConvertFromString(), specifying the string control
  • call LoadPanel() then InstallPopup()
  • the password panel will then be displayed as a modal dialog box
  • in the OK button callback get the entered password by calling PasswordCtrl_GetAttribute()

Cheers,
Colin.

0 Kudos
Message 2 of 22
(6,492 Views)

Of course, thanks.

Tried it, but unfortunatly it's not working.

My actual code is this:

if ((panelHandlePassword = LoadPanel (panelHandle, "ATS.uir", PanelPass)) <0 )  return -1; 
PasswordCtrl_ConvertFromString (panelHandlePassword, PanelPass_PasswordString);
InstallPopup(panelHandlePassword); 
MessagePopup("","");

My code still continues on after I have called the password popup panel.

The password panel pops up fine, but so does the blank message box on the next line of code!

On a normal popup like PromptPopup() the code stops at that point and waits for a response, that's what I want.

Any idea what's going on?

Thanks

Dave 🙂

0 Kudos
Message 3 of 22
(6,483 Views)
I figured it out.
Any panel (including a converted popup panel) will not wait for user input before continuing with the next line of code. Therefore you have to use a RunUserInterface() command to force the program to stop and wait on the currently active panel. The pre-programmed popup panels in CVI (e.g. PromptPopup()) must do it this as well I presume?
 
This is my working code:
if ((panelHandlePassword = LoadPanel (panelHandle, "ATS.uir", PanelPass)) <0 ) return -1;
 PasswordCtrl_ConvertFromString (panelHandlePassword, PanelPass_PasswordString);
 InstallPopup(panelHandlePassword);     
 SetActiveCtrl(panelHandlePassword,PanelPass_PasswordString);  
 RunUserInterface();    
 PasswordCtrl_GetAttribute(panelHandlePassword, PanelPass_PasswordString,ATTR_PASSWORD_VAL, s);
 DiscardPanel(panelHandlePassword);
My password panel OK button simply calls up QuitUserInterface(0) which returns control back to the next line of code after RunUserInterface()
The string s holds the decoded password text. Exactly what I wanted.
 
I must admit, I had to look at someone else's code to figure it out, and then it took me a while to figure out that the returned handle value from RunUserInterface() is not unique. RunUserInterface() returns a 0 even though I have called it previously at the start of my program.
 
Easy once you know, absolutely horrid when you don't!
 
Dave 🙂
0 Kudos
Message 4 of 22
(6,482 Views)

David,
InstallPopup simply displays a panel and forces user action on that panel, it does not "freeze" program execution on it. Normally it is associated to a "Close" button or something like this whose callback discards the popup, as if you were looping inside a closed circle whose exit is that button. To obtain this behaviour your InstallPopup must be at the end of a callback that exits leaving the popup displayed so that RunUserInterface (called at program start) can manage events on that panel. There is absolutely no need of a second call to RunUserInterface which man make normal event processing confused.

In case of a password request, I personally hate to spread the code in multiple callbacks, so I do prefere using GetUserEvents () function inside a loop to manage user actions on the passowrd request panel. The skeleton of the application will be as follows:

Create your password request panel with a string control (Important: set its mode as "normal", NOT "hot!), a abort button and ok button (set as HOT).

Load the password request panel
InstallPopup
While (1) {
   GetUserEvent (1, &pnl, &ctl);
   if (pnl == PANEL_ABORT) {
      // User has quitted: discard the panel
      DiscardPanel ();
      return 0;     //Usually this code in inside a callback
   }
   else if (ctl == PANEL_OK) {
      // Retrieve and test password value
      If (password_ok) {
         DiscardPanel ();
         break;
      }
   }
}

Hope this helps
Roberto

Message Edited by Roberto Bozzolo on 03-01-2006 07:05 AM



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 5 of 22
(6,482 Views)
I forgot it in my previous message: in password request panel, DO NOT associate any callback neither to the string control nor to the buttons!


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 6 of 22
(6,475 Views)
Alternatively, if you only want to stop user events being processed;

After;

InstallPopup( passwordHandle );

You can loop as follows;

while(GetActivePanel() == passwordHandle){
ProcessSystemEvents();
}

The callbacks dealing with the password panel simply need to include;

RemovePopup(0);
--
Regards,

John Cameron.
Type softly, read gently.
0 Kudos
Message 7 of 22
(6,481 Views)

Thanks guys.

Those solutions sound a bit cleaner than the 2nd instance of RunUserInterface(). Although for my application it appears to work just fine.

Does anyone know how the CVI popup routines like PromptPopup() actually do it?

Dave 🙂

0 Kudos
Message 8 of 22
(6,434 Views)

I used Johns suggestion as it seems more elegant and it works a treat.

My final code is :

if ((panelHandlePassword = LoadPanel (panelHandle, "ATS.uir", PanelPass)) <0 ) return -1;
 PasswordCtrl_ConvertFromString (panelHandlePassword, PanelPass_PasswordString);
 InstallPopup(panelHandlePassword);     
 SetActiveCtrl(panelHandlePassword,PanelPass_PasswordString);  
 while(GetActivePanel()==panelHandlePassword)
 ;    
 PasswordCtrl_GetAttribute(panelHandlePassword, PanelPass_PasswordString,ATTR_PASSWORD_VAL, s);
 DiscardPanel(panelHandlePassword);
0 Kudos
Message 9 of 22
(6,424 Views)

I used Johns suggestion as it seems more elegant and it works a treat.

My final code is :

if ((panelHandlePassword = LoadPanel (panelHandle, "ATS.uir", PanelPass)) <0 ) return -1;
 PasswordCtrl_ConvertFromString (panelHandlePassword, PanelPass_PasswordString);
 InstallPopup(panelHandlePassword);     
 SetActiveCtrl(panelHandlePassword,PanelPass_PasswordString);  
 while(GetActivePanel()==panelHandlePassword)
  ;    
 PasswordCtrl_GetAttribute(panelHandlePassword, PanelPass_PasswordString,ATTR_PASSWORD_VAL, s);
 DiscardPanel(panelHandlePassword);
0 Kudos
Message 10 of 22
(6,425 Views)