public void DeleteAccount(string username, string password) { User input = UserService.Instance.GetUser(username); if (input != null) { string HashPass = SecureConverter.Hash(password); if (input.Password == HashPass) { UserService.Instance.DeleteUser(input); PasswordHistoryService.Instance.DeleteUserFromPassHistory(input.Username); string srvCertCN = "wcfservice"; NetTcpBinding binding = new NetTcpBinding(); binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; X509Certificate2 srvCert = CertManager.GetCertificateFromStorage(StoreName.TrustedPeople, StoreLocation.LocalMachine, srvCertCN); EndpointAddress address = new EndpointAddress(new Uri("net.tcp://localhost:9000/AuthenticationService"), new X509CertificateEndpointIdentity(srvCert)); using (AuthenticationServiceAuditProxy proxy = new AuthenticationServiceAuditProxy(binding, address)) { proxy.LogOutClient(username, "Your account has been deleted. You are logged out!"); } } else { Console.WriteLine("Wrong password"); } } else { Console.WriteLine("This user does not exist"); } }
public void ResetPassword(string username, string password) { List <string> loggedIn = new List <string>(); User user = UserService.Instance.GetUser(username); if (user != null) { if (PasswordPolicy.ValidatePasswordComplex(password)) { string newPass2 = SecureConverter.Hash(password); if (PasswordPolicy.ValidatePasswordHistory(username, newPass2)) { UserService.Instance.DeleteUser(user); user.Password = newPass2; user.CreatePass = DateTime.Now; UserService.Instance.AddToBase(user); PasswordHistoryService.Instance.AddToBase(user.Username, newPass2); string srvCertCN = "wcfservice"; NetTcpBinding binding = new NetTcpBinding(); binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; X509Certificate2 srvCert = CertManager.GetCertificateFromStorage(StoreName.TrustedPeople, StoreLocation.LocalMachine, srvCertCN); EndpointAddress address = new EndpointAddress(new Uri("net.tcp://localhost:9000/AuthenticationService"), new X509CertificateEndpointIdentity(srvCert)); using (AuthenticationServiceAuditProxy proxy = new AuthenticationServiceAuditProxy(binding, address)) { loggedIn = proxy.GetAllLoggedUsers(); if (loggedIn.Contains(username)) { proxy.LogOutClient(username, "Your password had been changed by admin. You are logged out!"); } } } else { Console.WriteLine("This password has been used too many times"); } } else { Console.WriteLine("This password must contain numbers and length must be 5 characters"); } } else { Console.WriteLine("User does not exist"); } }
static void ValidatePasTime() { string srvCertCN = "wcfservice"; NetTcpBinding binding = new NetTcpBinding(); binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; X509Certificate2 srvCert = CertManager.GetCertificateFromStorage(StoreName.TrustedPeople, StoreLocation.LocalMachine, srvCertCN); EndpointAddress address = new EndpointAddress(new Uri("net.tcp://localhost:9000/AuthenticationService"), new X509CertificateEndpointIdentity(srvCert)); using (AuthenticationServiceAuditProxy proxy = new AuthenticationServiceAuditProxy(binding, address)) { while (true) { try { List <string> loggedUsers = proxy.GetAllLoggedUsers(); Console.WriteLine($"Ima ih {loggedUsers.Count}"); foreach (string user in loggedUsers) { if (PasswordPolicy.ValidatePasswordTime(UserService.Instance.GetUser(user))) { proxy.LogOutClient(user, "Your password has been expired.Please conntact admin.You will be logged out..."); } } } catch (Exception e) { MyException ex = new MyException(); ex.Message = e.Message; throw new FaultException <MyException>(ex, new FaultReason(ex.Message)); } Thread.Sleep(PasswordPolicy.CheckPassword()); } } }