Example Code

Password-Protecting Tabs in a Tab Control using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
The example demonstrates Password Lock in Tab Control.


Description
The example Tab Control has Home and Config tabs. The Home tab is freely available to all users, but the Config tab is password-protected with a simple password ("engineer"). Any time the Config tab is selected, the user will be prompted for the password, and will be unable to see certain controls if the password is not entered or is invalid.

 

The accompanying code is straightforward. After setting an initial tab to be visible and hiding the sensitive controls, the VI enters a continuous While Loop to wait for user input. Input is handled by an Event Structure, which contains event handlers for a Value Change event on the Tab Control and a Value Change event on the Stop button. When the user clicks a new tab on the Tab Control, the Tab Control Value Change event executes, and uses a Case structure to handle the tab chosen by the user. In this example, changing to the Home tab (an unprotected tab) simply hides the sensitive data.

 

Changing to the Config tab will call the Request Password Express VI and execute one of two cases based on whether the password was correct or not. If the password is correct, the True case will execute, and the sensitive data will be made visible. If the password is incorrect, the sensitive data remains hidden.

 

Finally, an event handler for a Value Change on the Stop button allows the loop to exit when the user chooses to stop the VI.

 

Adding more unprotected or protected tabs would be as simple as adding new tabs to the Tab Control and then creating cases for them in the Case Structure in the Tab Control Value Change event handler.


Requirements

  • LabVIEW Base Development System 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Run the VI.
  2. Notice that when the Config tab is selected, a password prompt appears.
  3. Enter an incorrect password (anything other than "engineer") and notice that nothing is visible on the tab.
  4. Click over to the Home tab, then back to the Config tab.
  5. When the password prompt appears, enter "engineer" as the password.
  6. Notice that the control on the Config tab is now visible.

 

Additional Information or References

VI Front Panel
fig1.png

VI Block Diagram

 fig2.png

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
crossrulz
Knight of NI Knight of NI
Knight of NI
on

First of all, you initially have the sensitive data visible.  Your constant outside of the while loop is wrong (should be a FALSE).

There's no need for the wait due to the event structure.

It is best to put your controls in the their respective event cases.  This will also allow the stop button to reset since it is set to latch.

Otherwise, it is a good concept - one I've implemented many times.  Good job.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Daniel-E
NI Employee (retired)
on

Hey crossrulz, thanks for the feedback! I've updated the example to reflect the changes you suggested.

crossrulz
Knight of NI Knight of NI
Knight of NI
on

Not quite.  The stop terminal should be in the Stop Value Changed event.  I would also put the tab terminal in the Tab Control Value Change event (mostly for consistancy).



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Daniel-E
NI Employee (retired)
on

Done!

tangjh88
Member
Member
on

Hi,

How can i change the name of tab " config" to Authority?

skybound
Member
Member
on

Password control was working in XP but stopped working in Windows 7.  It has to be in the permission in Windows.  Where is the password information stored so I can make sure the permissions are set to read write?