PDA

View Full Version : Multi-use UForm - can it be improved upon?



pr1asd
10-18-2019, 08:55 AM
Hi,

I am writing some VBA which will require the user to confirm their credentials in different places depending on what they are doing.

I don't really want to make a different Username/Password UForm for each one (because there would be different actions once the user has authenticated their credentials).

I have made something that works (see attached. Note: the target VBA was recorded). But this seems odd to me and not very elegant...

Can anyone help me make this better?

Thanks

Aman

SamT
10-18-2019, 10:01 AM
Add a new sheet. Three columns: App_UserName; UserName (For their Password User Name); And PW. If their UserName is the same as their Windows Login Name (App_UserName) You won't need the App_UserName column.
List the names and Passwords.
In the VBA Editor, use the Properties to set that sheet's Visible Property to xlVeryHidden

In the ThisWorkbook Code page
Dim GoodPw As Boolean

In VBA, Application.UserName returns the windows login name

In the Password UserForm, set GoodPW = True. Anywhere else just use
If Not GoodPW Then
MsgBox "you need to use a Password"
Exit Sub
End If

Artik
10-20-2019, 03:27 AM
In VBA, Application.UserName returns the windows login name

SamT, what's the matter with you? ;)


pr1asd, it is not a good practice to store passwords in an explicit form in a workbook.
In the attached example, passwords are stored as a hash function (MD5).
I devastated your project a little. :)


Artik

snb
10-20-2019, 09:37 AM
If you need the macrorecorder for this, you'd better shy away from any (fake) protection in Excel.

SamT
10-20-2019, 04:41 PM
Aetik, that belongs on Stack Overflow, not VBA Express.