lior
lior

Reputation: 61

How to check if item exist in DB on Windows Azure mobile service project

I'm trying to look for Person with username and password and if exist on DB to enter the application.

I don't know what to use to find my items on DB and this is my try:

private async void bt_login_Click(object sender, RoutedEventArgs e) {

        var temperson = new Person();
        temperson.UserName = tb_username.Text;
        temperson.Password = tb_password.Text;
        foreach (var person in personTable)
        {
            if((person.UserName == tb_username.Text) && (person.Password == tb_password.Text))
                NavigationService.Navigate(new Uri("/Pages/FacebookLoginPage.xaml", UriKind.Relative));

        }

    }

This is how persontabel define

private IMobileServiceTable personTable = App.MobileService.GetTable();

Upvotes: 0

Views: 182

Answers (1)

David Makogon
David Makogon

Reputation: 71110

I think this question is much more generic and unrelated to mobile services. As it stands, you've written client-side code to march through server-side data, hunting for a given Person. What happens when you have 10,000 Persons? A million? This is much better dealt with server-side (either via app-tier code or in a stored procedure), but... that's just my opinion.

If you're really trying to use Mobile Services for this task, then build some type of login/authentication API call into your mobile service stack. Pass the username and [hashed/encrypted] password to the mobile stack, have it search for the user via db query, perform password-match, and return something that tells you whether the Person was found+authenticated. How you do that is really up to you - lots of ways, and there's no single right answer.

Upvotes: 1

Related Questions