Ejemplo n.º 1
0
        private async void Submit()
        {
            var user = await FirebaseHelper.GetUser(_email);

            if (!(string.IsNullOrEmpty(_password) | string.IsNullOrEmpty(_passwordConfirmation)))
            {
                if (_password == _passwordConfirmation)
                {
                    bool PasswordValid = IsValidPassword(_password);

                    if (PasswordValid == true)
                    {
                        string hashedPassword = string.Empty;
                        hashedPassword = HashPassword(_password);

                        try
                        {
                            await FirebaseHelper.UpdateUser(user.UserID, user.FirstName, user.Surname, user.Email, hashedPassword, user.Key, user.Salt);

                            await App.Current.MainPage.DisplayAlert("Success", "Password has been changed", "Ok");

                            await App.Current.MainPage.Navigation.PopAsync();
                        }
                        catch (Exception e)
                        {
                            await App.Current.MainPage.DisplayAlert("Error", "Password change failed, please try again", "Ok");
                        }
                    }
                    else
                    {
                        await App.Current.MainPage.DisplayAlert("Invalid Password", "Please enter a password in line with requirements", "OK");
                    }
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Error", "Passwords must match", "Ok");
                }
            }
            else
            {
                await App.Current.MainPage.DisplayAlert("Empty Values", "Fields should not be empty", "Ok");
            }
        }
Ejemplo n.º 2
0
        private async void Submit()
        {
            if (string.IsNullOrEmpty(_email) || string.IsNullOrEmpty(_emailConfirmation))
            {
                await App.Current.MainPage.DisplayAlert("Empty values error", "Both Email and Email Confirmation must not be empty", "Ok");
            }
            else
            {
                if (_email != _emailConfirmation)
                {
                    await App.Current.MainPage.DisplayAlert("Matching values error", "Both Email and Email Confirmation must match", "Ok");
                }
                else
                {
                    var user = await FirebaseHelper.GetUser(_email);

                    if (user == null)
                    {
                        await App.Current.MainPage.DisplayAlert("Email address not found", "Please ensure you have provided the correct email address used with your account", "Ok");
                    }
                    else
                    {
                        //reset users password to random password
                        try
                        {
                            string password       = "******";
                            string hashedPassword = string.Empty;
                            hashedPassword = HashPassword(password);
                            await FirebaseHelper.UpdateUser(user.UserID, user.FirstName, user.Surname, user.Email, hashedPassword, user.Key, user.Salt);
                        }
                        catch
                        {
                            await App.Current.MainPage.DisplayAlert("Password reset error", "Failed to reset password, please try again", "Ok");
                        }

                        //send user an email telling them new password and advise to reset it straight away after logging in
                        try
                        {
                            MailMessage mail       = new MailMessage();
                            SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                            mail.From = new MailAddress("*****@*****.**");
                            mail.To.Add(user.Email);
                            mail.Subject = "Your Temporary Vault Password";
                            mail.Body    = "Dear " + user.FirstName + ", \n Your new temporary password is Cherry123. Please login with your email and this temporary password and change your password immediately after logging in. \n  Kind Regards \n Vault Management Team";

                            SmtpServer.Port                  = 587;
                            SmtpServer.Host                  = "smtp.gmail.com";
                            SmtpServer.EnableSsl             = true;
                            SmtpServer.UseDefaultCredentials = false;
                            SmtpServer.Credentials           = new System.Net.NetworkCredential("", "");//insert creds when want to use
                            SmtpServer.Send(mail);

                            await App.Current.MainPage.DisplayAlert("Password reset success", "Please check your email inbox or junk folder for the email sent out to you", "Ok");

                            await App.Current.MainPage.Navigation.PopAsync();
                        }
                        catch
                        {
                            await App.Current.MainPage.DisplayAlert("Email sending error", "Failed to send email, please try again", "Ok");
                        }
                    }
                }
            }
        }