Exemple #1
0
        public async Task <VmUser> ValidateUserLogin(VmUser userLogin)
        {
            VmUser vUser = null;

            if (!string.IsNullOrEmpty(userLogin.UserEmail) && !string.IsNullOrEmpty(userLogin.UserEncyryptedKey))
            {
                var userDetails = await _dbContext.User.AsNoTracking().Where(x => x.user_email == userLogin.UserEmail).FirstOrDefaultAsync();

                if (userDetails != null)
                {
                    var masterKey  = userDetails.user_email.Substring(2, 4);
                    var message    = _encryption.DecryptText(userDetails.user_encryptedmessage, masterKey);
                    var newMessage = _encryption.EncryptText(userLogin.UserEncyryptedKey, message);
                    var result     = _encryption.CompareStrings(userDetails.user_encryptedkey, newMessage, message);

                    if (result)
                    {
                        vUser = new VmUser(userDetails);

                        vUser.DecryptedUserEmail = vUser.UserEmail;
                        vUser.UserEmail          = _encryption.EncryptText(vUser.DecryptedUserEmail, ATMConstants.emailEncKey);
                        return(vUser);
                    }
                    else
                    {
                        vUser         = new VmUser();
                        vUser.Message = "Invalid email/password";
                    }
                }
                else
                {
                    vUser         = new VmUser();
                    vUser.Message = "User not found";
                }
            }
            else
            {
                vUser         = new VmUser();
                vUser.Message = "Invalid email/password";
            }

            return(vUser);
        }