예제 #1
0
        async void SaveUser()
        {
            if (Password == RepeatedPassword)
            {
                AesCrypto cryptModul = new AesCrypto();
                User[]    prihlas;
                try
                {
                    prihlas = _context.Users.Where(b => b.Login == Username).ToArray();
                }
                catch (Exception e)
                {
                    throw e;
                }

                bool empty = false;
                try
                {
                    if (prihlas[0].Login == Username)
                    {
                        empty = true;
                    }
                }
                catch (Exception e)
                {
                    //throw e;
                }


                //System.Diagnostics.Debug.WriteLine("prihlas " + prihlas[1].Login);

                if (empty)
                {
                    UserDialogs.Instance.Alert("Login", "Obsadené meno", "OK");
                    prihlas = null;
                }
                else
                {
                    byte[] kluc   = cryptModul.GetKey();
                    string klucik = Convert.ToBase64String(kluc);


                    byte[] klucIV   = cryptModul.GetIV();
                    string klucikIV = Convert.ToBase64String(klucIV);


                    User user = new User
                    {
                        Login    = Username,
                        Password = Password,
                        Key      = klucik,
                        IV       = klucikIV,
                    };
                    _context.Users.Add(user);


                    try
                    {
                        _context.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                    UserDialogs.Instance.Alert("Úspešná registrácia", "Registrácia", "OK");
                    await Application.Current.MainPage.Navigation.PopAsync();
                }
            }
            else
            {
                UserDialogs.Instance.Alert("Heslo sa nezhoduje", "Chyba", "OK");
            }
        }