Windows Develop Bookmark and Share   
 index > Windows Forms General > getting custom credentials from the user
 

getting custom credentials from the user

Is there a controll (or common dialog) that would let me ask a user for a set of credentials?

I could just make a form with a textbox but I would like the password to be in a securestring instead of a normal string.

Jacob
wagnerjp  Wednesday, September 02, 2009 11:56 PM
The reason for the credentials is to use to connect to a SQL Server instance using SMO. The connection requires a SecureString object for the password. A normal string can be converted to a SecureString but if I do so then I am eliminating all of the benefits of SecureString (other than its requierment in the code I am calling, of course).

I expanded my search and fount two solutions that will work. One is TextBox for inclusion in a form, the other is based on CommonDialog and provides the standard windows dialog (it is really a managed wrapper for CredUIPromptForCredentials) but returns the resulting pasword as a SecureString.

I haven't decided which I will use yet, but I think that either will do what I need.

for future readers, the two controlls can be found at:

SecurePasswordTextBox
http://weblogs.asp.net/pglavich/archive/2006/10/29/Secure-TextBox-Updated.aspx
OR
http://www.theglavs.com/Downloads.aspx

CredentialsDialog
http://weblogs.asp.net/hernandl/archive/2005/11/21/usercredentialsdialog.aspx

Jacob
  • Marked As Answer bywagnerjp Monday, September 14, 2009 2:30 PM
  •  
wagnerjp  Monday, September 14, 2009 2:29 PM
Depending on what you are trying to do, you could use the login credentials from Windows. Then you don't need to ask again.

If you really do need another user name and password, you can set a TextBox PasswordChar property to prevent it from being displayed.

Finally, here are some links regarding securestring and passwords:

http://dotnet.org.za/markn/archive/2008/10/04/handling-passwords.aspx

http://blogs.msdn.com/fpintos/archive/2009/06/12/how-to-properly-convert-securestring-to-string.aspx

Hope this helps.

www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Thursday, September 03, 2009 5:04 AM
Hi Jacob,

Could you be more specific on what kind of credentials you want to get through the dialog? Is it Windows credential or something else?

There is a Windows security API function you might be interested in: CredUIPromptForCredentials Function.To use it, you need to p/invoke though.

Any further questions, please let me know.

Thanks,
Jie
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

If you have any feedback, please tell us.

The CodeFx Project
My Blog (in Simplified Chinese)
Wang, Jie  Thursday, September 03, 2009 9:01 AM
The reason for the credentials is to use to connect to a SQL Server instance using SMO. The connection requires a SecureString object for the password. A normal string can be converted to a SecureString but if I do so then I am eliminating all of the benefits of SecureString (other than its requierment in the code I am calling, of course).

I expanded my search and fount two solutions that will work. One is TextBox for inclusion in a form, the other is based on CommonDialog and provides the standard windows dialog (it is really a managed wrapper for CredUIPromptForCredentials) but returns the resulting pasword as a SecureString.

I haven't decided which I will use yet, but I think that either will do what I need.

for future readers, the two controlls can be found at:

SecurePasswordTextBox
http://weblogs.asp.net/pglavich/archive/2006/10/29/Secure-TextBox-Updated.aspx
OR
http://www.theglavs.com/Downloads.aspx

CredentialsDialog
http://weblogs.asp.net/hernandl/archive/2005/11/21/usercredentialsdialog.aspx

Jacob
  • Marked As Answer bywagnerjp Monday, September 14, 2009 2:30 PM
  •  
wagnerjp  Monday, September 14, 2009 2:29 PM

You can use google to search for other answers

Custom Search

More Threads

• User session logoff from within Windows form C# app.
• custom radio button = trap OnPaint to change appearance
• Using the WebBrowser as an HTML editor
• CType(listX.SubItems(Column).Text, Int32).CompareTo(CType(listY.SubItems(Column).Text, Int32))
• Scrollbar and dynamic content
• Hold down Mouse button for 3 seconds, then stuff happens...
• ListView Control Problems
• accessing a toolstripmenuitem thru a different form
• how to pull all users/groups in a computer?
• Change style of RadioButtons so that they look as regular buttons