By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,302 Members | 3,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,302 IT Pros & Developers. It's quick & easy.

How do you authenticate a user and pswd for local accounts from windowsforms?

P: n/a

I would think this would be very, very easy but in the 50 searches
I've done I haven't found anything.

If our application requires login and that user/password be a local
windows account or more detailed, a user that has been added to the
Power Users group that is either a local account or a active directory
account how do I authenticate?

I've found code that seems to do this against Active Directory

public static bool LogonValid(string userName, string password) {
DirectoryEntry de = new DirectoryEntry(null, domain + "\\" +
userName, password);
try {
object o = de.NativeObject;
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = "samaccountname=" + userName;
ds.PropertiesToLoad.Add("cn");
SearchResult sr = ds.FindOne();
if(sr == null) throw new Exception();
return true;
} catch {
return false;
}
}

but this doesn't work for local accounts.

how does one authenticate against local accounts in a c#/windows forms
application?

thanks
mike
Jun 22 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Michael Howes wrote:
>
I would think this would be very, very easy but in the 50 searches
I've done I haven't found anything.

If our application requires login and that user/password be a local
windows account or more detailed, a user that has been added to the
Power Users group that is either a local account or a active directory
account how do I authenticate?

I've found code that seems to do this against Active Directory

public static bool LogonValid(string userName, string password) {
DirectoryEntry de = new DirectoryEntry(null, domain + "\\" +
userName, password);
try {
object o = de.NativeObject;
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = "samaccountname=" + userName;
ds.PropertiesToLoad.Add("cn");
SearchResult sr = ds.FindOne();
if(sr == null) throw new Exception();
return true;
} catch {
return false;
}
}

but this doesn't work for local accounts.

how does one authenticate against local accounts in a c#/windows forms
application?

thanks
mike
Hi Mike,

I believe the API you're looking for is LogonUser. Local windows accounts
aren't part of an AD system.

Take a look at this page to get started:
http://www.codeproject.com/useritems...tion_in_Ne.asp

This example shows how to impersonate a user, but it contains an example of
using the LogonUser API in managed code.

--
Tom Spink
University of Edinburgh
Jun 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.