简体   繁体   中英

Authenticate credentials remote server

I'm trying to check if the username/password for a remote computer, entered by a user on a WPF form are correct.

I have those strings: username, password and ip address.

I saw something about about "DirectoryEntry" but couldn't get it to work - the user is always authenticated even when the password is incorrect.

Any ideas?

There are multiple ways, but the way I've done it before is like this (using DirectoryEntry), it goes like this:

string ldapConnectionString = @"LDAP://[domain_server]/CN=Users,DC=[domain]"

using (var de = new DirectoryEntry(
    ldapConnectionString, "username", "password", 
    AuthenticationTypes.Secure))
{
    return de.NativeObject != null; // if not null -> user is valid
}

Edit: What this code will do is, validate a combination of a username/password against active directory. I think I misunderstood you (if what you mean is, to see if a user CAN connect to a particular server -> as in HAS PERMISSION to, I'm not quite sure how to do that, or even if it's possible).

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