Exemplo n.º 1
0
        public static void LoginUser()
        {
            string    username;
            string    password;
            string    encrypted;
            bool      loginSuccess;
            const int allowedRetries = 3;
            int       retries        = 1;

            do
            {
                Logger.OutputInformation("Please Log-in.");
                username  = GetConsoleString("user name");
                password  = ReadPasswordLine("password");
                encrypted = Encode_Decode.Encrypt(password);

                /*                string decrypted = Encode_Decode.Decrypt(encrypted);
                 *              Console.WriteLine("password = "******" encrypted = " + encrypted + " decrypted = " + decrypted);*/
                Factory       factory = new Factory();
                List <object> pars    = new List <object>();
                pars.Add(username);
                pars.Add(encrypted);
                LoginUserCommand c = (LoginUserCommand)factory.GetCommand(CommandType.Login, pars);
                if (c != null)
                {
                    loginSuccess = c.Apply();
                    Commands.Add(c);
                }
                else
                {
                    loginSuccess = false;
                }
                if (!loginSuccess)
                {
                    Logger.OutputInformation("Failed to login " + username);
                }
                ++retries;
            }while (!loginSuccess && retries <= allowedRetries);
            if (!loginSuccess)
            {
                Logger.OutputInformation("Failure to login max " + allowedRetries + " attempts allowed.");
            }

            _Screens.DisplayBooksScreen();
        }
Exemplo n.º 2
0
        // Encrypt
        public string CreateInvitationCode(string userid, int lifeInHours = 48)
        {
            try
            {
                var           life    = DateTime.UtcNow.AddHours(lifeInHours);
                InvitationDto results = new InvitationDto()
                {
                    userId = userid,
                    expire = M.DateTimeToUnixTime(life)
                };

                var    str     = InvitationToString(results);
                string key     = appSettings.jwt.SecretKey;
                string encoded = Encode_Decode.Encrypt(str, key);
                return(encoded);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public static void ChangeUserPassword()
        {
            string userName;
            string password;
            string encryptedPassword;
            string newPassword;
            string newEncryptedPassword;
            string repeatPassword;
            string repeatEncryptedPassword;


            Logger.OutputInformation("Please Change User Password.");

            userName                = GetConsoleString("User Name");
            password                = ReadPasswordLine("Old Password");
            encryptedPassword       = Encode_Decode.Encrypt(password);
            newPassword             = ReadPasswordLine("New Password");
            newEncryptedPassword    = Encode_Decode.Encrypt(newPassword);
            repeatPassword          = ReadPasswordLine("Repeat New Password");
            repeatEncryptedPassword = Encode_Decode.Encrypt(repeatPassword);

            Factory       factory = new Factory();
            List <object> pars    = new List <object>();

            pars.Add(userName);
            pars.Add(encryptedPassword);
            pars.Add(newEncryptedPassword);
            pars.Add(repeatEncryptedPassword);
            ChangeUserPasswordCommand c = (ChangeUserPasswordCommand)factory.GetCommand(CommandType.ChangeUserPassword, pars);

            if (c != null)
            {
                c.Apply();
                Commands.Add(c);
            }
        }
Exemplo n.º 4
0
        public static void RegisterNewUser()
        {
            string FirstName;
            string MiddleName;
            string Surname;
            string Password;
            string UserName;
            string Email;
            string Encrypted;

            Logger.OutputInformation("Please Register a New User.");
            FirstName  = GetConsoleString("First Name");
            MiddleName = GetConsoleString("Middle Name");
            Surname    = GetConsoleString("Surname");
            Password   = ReadPasswordLine("Password");
            UserName   = GetConsoleString("User Name");
            Email      = GetConsoleString("Email");
            Encrypted  = Encode_Decode.Encrypt(Password);

            Factory       factory = new Factory();
            List <object> pars    = new List <object>();

            pars.Add(FirstName);
            pars.Add(MiddleName);
            pars.Add(Surname);
            pars.Add(Encrypted);
            pars.Add(UserName);
            pars.Add(Email);
            RegisterNewUserCommand c = (RegisterNewUserCommand)factory.GetCommand(CommandType.RegisterNewUser, pars);

            if (c != null)
            {
                c.Apply();
                Commands.Add(c);
            }
        }