Last active
September 14, 2015 21:04
-
-
Save yareally/533fc167debc6fe31775 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ServicesTool2.ViewModel | |
{ | |
using System; | |
using System.DirectoryServices.AccountManagement; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Input; | |
using GalaSoft.MvvmLight; | |
using GalaSoft.MvvmLight.CommandWpf; | |
public class ServiceAccountViewModel : ViewModelBase | |
{ | |
public ServiceAccountViewModel() | |
{ | |
Domain = Environment.UserDomainName; | |
} | |
public string Domain { get; set; } | |
public string Username { get; set; } | |
public ICommand VerifyCommand => new RelayCommand<object>(Verify); | |
private async Task Verify(object parameter) | |
{ | |
var passwordBox = parameter as PasswordBox; | |
if (passwordBox != null) { | |
string password = passwordBox.Password; | |
try { | |
using (var pc = new PrincipalContext(ContextType.Domain, Domain)) { | |
bool isValid = await Task<bool>.Factory.StartNew(() => pc.ValidateCredentials(Username, password)); | |
MessageBox.Show(isValid ? "success" : "failure"); | |
} | |
} catch (Exception ex) { | |
MessageBox.Show(ex.Message); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment