How to reset password for login?

sjinsjin Member ✭✭

After i log in my xamarin page, i want to change my password.
I am new how to make that page using my Api framework.

Thank you.
public async void SignInProcedure(object sender, EventArgs e) {

    User user = new User(Entry_phone.Text, Entry_Password.Text);
    if (user.CheckInformation())
    {
        HttpClient client = new HttpClient();
        var uri = new Uri(string.Format("http://4a99cffe.ngrok.io/api/Login?phone=" + Entry_phone.Text + "&password=" + Entry_Password.Text));
        HttpResponseMessage response; ;
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        response = await client.GetAsync(uri);

        if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
        {
            var errorMessage1 = response.Content.ReadAsStringAsync().Result.Replace("\\", "").Trim(new char[1] { '"' });
            await DisplayAlert("Login", "Log in success", "ok");
            await Navigation.PushAsync(new Customerinfo(Entry_phone.Text));
        }
        else
        {
            var errorMessage1 = response.Content.ReadAsStringAsync().Result.Replace("\\", "").Trim(new char[1] { '"' });
            await DisplayAlert("Login", "", "Again");
        }




        Entry_phone.Text = string.Empty;
        Entry_Password.Text = string.Empty;
    }
    else
    {
        await DisplayAlert("Login", "Not correnct Login information", "ok");
    }

That is my api

[HttpGet]
[ActionName("XAMARIN_Login")]
public HttpResponseMessage Xamarin_Login(string phone, string password)
{
    var user = db.customers.Where(x => x.Phone == phone && x.Password == password).FirstOrDefault();
    if (user == null)
    {
        return Request.CreateResponse(HttpStatusCode.Unauthorized, "Please Enter valid UserName and Password");
    }
    else
    {

        return Request.CreateResponse(HttpStatusCode.Accepted, "Success");
    }
}
Tagged:

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    You are trying to access your backend service with a phone number and password.
    There's nothing wrong with your Xamarin code part. If you can verify this user try to replace its password with a new one in the else statement:

    else
    {
        // Change the password here
        // ...
        return Request.CreateResponse(HttpStatusCode.Accepted, "Success");
    }
    
  • sjinsjin Member ✭✭
    What kind of code should i put backend and front end?
  • LandLuLandLu Member, Xamarin Team Xamurai

    Update the user's information and store it back in the db database.
    However, this is an Asp .Net issue it's best to raise issues here:
    https://forums.asp.net/

  • sjinsjin Member ✭✭

    how to bind data from Xamarin app to api?

    i mean if i input new value in Xamarin -> Api -> Sql server.
    i don't know which code Xamarin -> Api for data binding.

  • LandLuLandLu Member, Xamarin Team Xamurai
    edited January 17

    What do you mean "data binding"?
    I guess you are not meaning the technology in Forms: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/data-binding-basics.
    However, I noticed you had retrieved the data you needed from UI like:

    Entry_phone.Text
    Entry_Password.Text
    

    And you are using get request to access your server. All parts in Xamarin look pretty good now. What issues in Xamarin are you confused about?

  • sjinsjin Member ✭✭

    I mean fetch data from Xamarin App to Api Sql server.

    because if i input new password , Fetch Password data pass through Xamarin app to Api Sql server.
    else
    {
    // Change the password here // Fetch Password value at here. how to fetch my value from Xamarin app.
    // ...
    return Request.CreateResponse(HttpStatusCode.Accepted, "Success");
    }

  • LandLuLandLu Member, Xamarin Team Xamurai

    If the second parameter is used for verifying the user, we need to add a new parameter here for a new password like:

    public HttpResponseMessage Xamarin_Login(string phone, string password, string newpsw)
    {
        // ...
    }
    

    For Xamarin part, we need to add a new Entry there so that the user could type in a new password. And your request could be:

    var uri = new Uri(string.Format("http://4a99cffe.ngrok.io/api/Login?phone=" + Entry_phone.Text + "&password=" + Entry_Password.Text + "&newpsw=" + Entry_NewPsw.Text));
    
  • sjinsjin Member ✭✭

    Also should i add to Sql database Culumn"New Password"?

  • LandLuLandLu Member, Xamarin Team Xamurai

    I don't think so. We only need to update the existed user's password with a new password.
    The old password could be overridden in your database.

Sign In or Register to comment.