Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading windows login name and password (encrypted) 3

Status
Not open for further replies.

FatEric

IS-IT--Management
Nov 8, 2007
58
BE
Hi everyone,

Again I have a question. I'm writing a program with a login screen. In the login screen, a login and password has to be filled in. Now I want to read the login and password of the user the is logged in into windows (because the login and password giving into the program have to be exacly the same as those of windows)

I already found the code "environment.username" for the username, but the password I don't find. The password my be encrypted with md5 or so, I don't need to now it exacly (only the way it is encrypted), so I can match the password with the one giving in into the program.

Thanks in advance for any advies.

FatEric
 
You can't get the password out, in any form.
You can pass it in, and see if what you gave it was right.

It's a security feature to prevent a hacker from figuring out how to decrypt the password.

-Sometimes the answer to your question is the hack that works
 
Hi Qik3Coder,

Thanks for your reply, but could you tell me more specific where I can find the windows password (encrypted then) if that is what you mean with "You can pass it in, and see if what you gave it was right."

Cheers, FatEric
 
When you work with the DirectoryServices classes you create a object for dealing with the Active Directory.

You have to pass in Windows Account info, into the constructor. You pass in the Domain, Login name, and clear text password. If you are able to create an object you gave it the correct info. Beware though, you only get the standard 3 tries, then you have to unlock the account, by hand.


Just to restate, you cannot get the password out, in any form...

-Sometimes the answer to your question is the hack that works
 
One question -
If the user is already logged into Windows, and the credentials for your program have to match, then why are you asking them to login a second time? Just use the credentials for the current user.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hey everyone,

Sorry for the late reply, but I was unable to check to forum the last few days.

Each user indeed has to login under Windows with his username and password. Then this user may use the program I am writing. But when for example on other user uses that pc (normally it is not possible) he can also use the program if it is not protected by a login and password. That is why I want to protect the program again with a password and login. But I don't want to hardcode them into the program, I just want to read the out of the registry so I can use those things.

So I someone can tell me how I can read them out of the registry, I would help me a lot.

Thanks in advance for any reply.

Cheers, FatEric
 
Why don't you just use a config file (text,XML,encrypted) and store the specific user information there.

If you want to protect your program with a user name and password you are more likely than not going to have to create your own login database.

There's a reason its called a "Windows" password, because it's for WINDOWS.

-Sometimes the answer to your question is the hack that works
 
Are you looking to just validate the username/password combination? I have this scenerio for a program I wrote. The users log into Windows.. however, when they try to access my program, they must use their Windows username/password to log into the program. It will then go out and verify that the username/password is valid (returns true/false).

This verifies via Active Directory, but probably can be made to work with non-AD PCs... let me know if u want some sample code.

Chris Sutton
 
Hi csutton,

That is indeed what I wanted to do. Each 2 months we have to change our password for windows, so that would mean the I had the change each 2 months a database with login and password. I you could pass me that code, it would be very nice. Than I only have to create a database with the users would could use the program, and the see if the windows password and login match the ones giving into my prog.

Maybe you could sent them to my email too? fateric at gmail dot com.

Thanks in advance...

Cheers, FatEric
 
Here is the function... its active directory based... let me know if it helps...

---------------------

Private Function ValidateActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean
Dim Success As Boolean = False

Dim Entry As New System.DirectoryServices.DirectoryEntry("LDAP://" & Domain, Username, Password)
Dim Searcher As New System.DirectoryServices.DirectorySearcher(Entry)
Searcher.SearchScope = DirectoryServices.SearchScope.OneLevel
Try
Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne
Success = Not (Results Is Nothing)
Catch ex As Exception
Success = False
End Try

Return Success

End Function

Chris Sutton
 
Thanks csutton,

I will try it tomorrow at work. But I already tried to work with Directory services, but I didn't seem to find them in any library. Could you tell me where I could find it? I'm new to vb.net.

Thanks, FatEric
 
System.DirectoryServices

-Sometimes the answer to your question is the hack that works
 
Guys,

I tried to import System.DirectoryServices (Imports System.directoryServices) like I imported System.Windows.Form and System.Text, but then I get the message: "namespace or type 'DirectoryServices' for the imports 'System.DirectoryServices' cannot be found." Do I have to imports something else.

I'm working with Visual Studio .NET 2003. (Now i realise this is the 2005 forum, sorry). But any help is welcome.

Greetz, FatEric
 
Hi Christiaan,

And can you tell me how I should set the reference? I'm not familliar with vb.net.

Je mag ook altijd in het Nederlands antwoorden :) (You may also answer in Dutch :) )

Cheers, FatEric
 
Right Click on your project.
Add Reference
You should already be on the .Net tab

Hit S, to go to the S's
scroll down to System.DirectoryServices
Select it.
Then hit ok.

-Sometimes the answer to your question is the hack that works
 
Thanks Qik3Coder,

I learned something today. Hopefully now I can write the code and complete the project.

Also Christiaan and csutton, thanks for your help.

Cheers, FatEric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top