简体   繁体   中英

How to create a password protected button in a vb.net form

I have a VB.NET form that contains textboxes for the user to enter his details. I have a delete button in the same form that I want only the administrator or any authorized person to be able to use.

Basically, I want to make the delete button password protected so that the normal user can't delete any of his details. only the admin who has the admin password can delete it.

Is it possible to create a password protected button? I searched on the Internet but couldn't find any links that would help me.

Thanks

From a usability perspective I'd suggest a 'better' way to implement it would be to use some sort of role-based model, whereby the user authenticates when they begin using the app and role-specific form elements are then displayed accordingly.

If you really want a password to be entered to use a button, why not leave it enabled and in the click event handler, show a password-capture form? You only execute the rest of the code if the password is correct, else the event gets cancelled.

My friend try this... CODE *Note:You should start the form with the delete button not enabled

Let textbox1 contain password and button1 is the Delete button

Dim a=textbox1.text
Dim password="admin123"

If a=password Then
    button1.Enable=True
Else
    button2.enable=false
End if
dim as user as string
dim as pass as integer

user ="Admin"
pass ="1234"
if (user = username.text And pass =password.text) then
msgbox"GOOD"
ELSE
msgbox"SORRY"
end if

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM