Exemple #1
0
        // Decryption
        public InvitationResult IsInvitationValid(string str)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(str))
                {
                    var results = new InvitationResult()
                    {
                        errors = "code is invalid"
                    };
                    return(results);
                }
                string key        = appSettings.jwt.SecretKey;
                string decoded    = Encode_Decode.Decrypt(str, key);
                var    invetation = StringToInvitation(decoded);
                bool   invalid    = M.isNull(invetation);
                if (invalid)
                {
                    var results = new InvitationResult()
                    {
                        errors = "code is invalid"
                    };
                    return(results);
                }
                var  now       = M.GetUtcInSecound();
                bool IsExpired = invetation.expire < now;
                if (IsExpired)
                {
                    var results = new InvitationResult()
                    {
                        errors = "code is expired"
                    };
                    return(results);
                }

                return(new InvitationResult()
                {
                    userId = invetation.userId
                });
            }
            catch (Exception ex)
            {
                var results = new InvitationResult()
                {
                    errors = "code is invalid"
                };
                return(results);
            }
        }
Exemple #2
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();
        }
Exemple #3
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);
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
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);
            }
        }