Exemple #1
0
        public void CreateAccount(string username, string password)
        {
            if (PasswordPolicy.ValidatePasswordComplex(password))
            {
                string HashPass             = SecureConverter.Hash(password);
                User   input                = new User(username, HashPass);
                ModelPasswordHistory mPassH = new ModelPasswordHistory(username, HashPass);

                bool retval = UserService.Instance.AddUser(input);

                if (retval == true)
                {
                    PasswordHistoryService.Instance.AddToBase(input.Username, input.Password);
                    Console.WriteLine($"User {input.Username} is successfully created");
                }
                else
                {
                    Console.WriteLine("This username is already taken");
                }
            }
            else
            {
                Console.WriteLine("This password must contain numbers and length must be 5 characters");
            }
        }
Exemple #2
0
        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");
            }
        }
Exemple #3
0
        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");
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            if (!IsUserInGroup())
            {
                NetTcpBinding myBinding = new NetTcpBinding();
                myBinding.Security.Mode = SecurityMode.Transport;
                myBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                myBinding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;

                string address = $"net.tcp://localhost:4006/AccountManagement";
                bool   exit    = false;

                using (AccountManagementProxy proxy = new AccountManagementProxy(myBinding, new EndpointAddress(new Uri(address))))
                {
                    while (!exit)
                    {
                        Console.WriteLine("\n Choose option: \n");
                        Console.WriteLine("1.Create Account \n");
                        Console.WriteLine("2.Delete Account \n");
                        Console.WriteLine("3.Reset Password \n");
                        string operation = Console.ReadLine();

                        switch (operation)
                        {
                        case "1":
                            Console.WriteLine("Enter username:"******"Enter password:"******"2":
                            Console.WriteLine("Enter username:"******"Enter password");
                            string pd = Console.ReadLine();
                            proxy.DeleteAccount(un, pd);
                            break;

                        case "3":
                            Console.WriteLine("Enter username:"******"Enter new password");
                            string pas = Console.ReadLine();
                            proxy.ResetPassword(us, pas);
                            break;

                        default:
                            exit = true;
                            Console.Clear();
                            Console.WriteLine("You choose to exit \n");
                            break;
                        }
                    }
                }
            }
            else
            {
                NetTcpBinding myBinding = new NetTcpBinding();
                myBinding.Security.Mode = SecurityMode.Transport;
                myBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                myBinding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;

                string address = $"net.tcp://localhost:4001/AuthenticationService";
                bool   exit    = false;
                using (AuthenticationServiceProxy proxy = new AuthenticationServiceProxy(myBinding, new EndpointAddress(new Uri(address))))
                {
                    NetTcpBinding myBindingManagement = new NetTcpBinding();
                    myBinding.Security.Mode = SecurityMode.Transport;
                    myBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                    myBinding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;

                    string addressManagement = $"net.tcp://localhost:4006/AccountManagement";
                    using (UserAccountManagementProxy proxyAccManagement = new UserAccountManagementProxy(myBindingManagement, new EndpointAddress(new Uri(addressManagement))))
                    {
                        while (!exit)
                        {
                            Console.WriteLine("\n Choose option: \n");
                            Console.WriteLine("1.Login \n");
                            Console.WriteLine("2.Reset password \n");
                            Console.WriteLine("3.Logout \n");
                            string operation = Console.ReadLine();

                            switch (operation)
                            {
                            case "1":
                                string   username = WindowsIdentity.GetCurrent().Name;
                                string[] pharse   = username.Split('\\');
                                Console.WriteLine($"Username is {pharse[1]}");
                                string pass    = WritePassword();
                                string newPass = SecureConverter.Hash(pass);
                                proxy.Login(pharse[1], newPass);
                                break;

                            case "2":
                                string   my_username = WindowsIdentity.GetCurrent().Name;
                                string[] pharse_user = my_username.Split('\\');
                                Console.WriteLine($"Username is {pharse_user[1]}");
                                Console.WriteLine("Enter old password:"******"Enter new password");
                                string new_password = Console.ReadLine();
                                proxyAccManagement.ResetPassword(pharse_user[1], newPass3, new_password);
                                break;

                            case "3":
                                string   name    = WindowsIdentity.GetCurrent().Name;
                                string[] pharse1 = name.Split('\\');
                                Console.WriteLine($"Username is {pharse1[1]}");
                                proxy.Logout(pharse1[1]);
                                break;

                            default:
                                exit = true;
                                Console.Clear();
                                Console.WriteLine("You choose to exit \n");
                                break;
                            }
                        }
                    }
                }
            }

            Console.ReadKey();
        }