Пример #1
0
        public static void ValidatePassword(string password)
        {
            var passwordHash = UserDataEncryption.Hash(password);

            if (passwordHash != CrossSecureStorage.Current.GetValue(PasswordHash))
            {
                throw new InvalidUserInputException(new ExcInfo(), Details.AuthInvalidUserInputPassword);
            }
        }
Пример #2
0
        public static void UpdateUser(string password)
        {
            ValidatePassword(password);

            var encryptionSalt = CrossSecureStorage.Current.GetValue(EncryptionSalt);
            var serializedUser = JsonConvert.SerializeObject(UserService.CurrentUser);
            var encryptedUser  = UserDataEncryption.Encrypt(serializedUser, password, encryptionSalt);

            CrossSecureStorage.Current.SetValue(CurrentUser, encryptedUser);
        }
Пример #3
0
        public static async Task LoginUser(string password)
        {
            ValidatePassword(password);

            var encryptionSalt = CrossSecureStorage.Current.GetValue(EncryptionSalt);
            var encryptedUser  = CrossSecureStorage.Current.GetValue(CurrentUser);

            var decryptedUser = JsonConvert.DeserializeObject <User>(UserDataEncryption.Decrypt(encryptedUser, password, encryptionSalt));

            decryptedUser.TangleMessenger = new TangleMessenger(new Seed(decryptedUser.Seed));
            decryptedUser.NtruKeyPair     = new NtruKex(true).CreateAsymmetricKeyPair(decryptedUser.Seed.ToLower(), decryptedUser.PublicKeyAddress);

            UserService.SetCurrentUser(decryptedUser);

            await GetUser();
        }
Пример #4
0
        public static void StoreUser(User user, string password)
        {
            if (!user.StoreSeed)
            {
                return;
            }

            var passwordHash   = UserDataEncryption.Hash(password);
            var encryptionSalt = Seed.Random().Value;

            CrossSecureStorage.Current.SetValue(PasswordHash, passwordHash);
            CrossSecureStorage.Current.SetValue(EncryptionSalt, encryptionSalt);

            var serializedUser = JsonConvert.SerializeObject(user);
            var encryptedUser  = UserDataEncryption.Encrypt(serializedUser, password, encryptionSalt);

            CrossSecureStorage.Current.SetValue(CurrentUser, encryptedUser);
        }