Click here to Skip to main content
15,889,859 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing a Windows mobile app,and i need to create some user roles,depending from the user.How can i set user roles,whats the best way to make this type of authentication?My app also connects to an outside sql server database.any idea,pls share!!

I have done this type of authentication,after creating a sql table with username and password colums,i chek if they exists...

C#
namespace MobileAPPLICATION
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button_login_Click(object sender, EventArgs e)
        {
            string _connectionstring = @"Server='.\SQLEXPRESS';Initial Catalog=LOGIN;USER ID=SA;PWD=;";
            SqlConnection _connection = new SqlConnection(_connectionstring);

            if (txtpwd.Text == "")
            {
                MessageBox.Show("Password is empty!");
                txtpwd.Focus();
            }
            else
            {
                    _connection.Open();

                           
                    string _sql = "SELECT * FROM [LOGIN] where username=@username and password=@password;";
                    SqlCommand _command = new SqlCommand(_sql, _connection);
                    _command.Parameters.AddWithValue("@username", txtusername.Text);
                    _command.Parameters.AddWithValue("@password", txtpwd.Text);

                    if (_command != null)
                    {

                        //commands to go to the main menu form!
                    }
                    else
                    {
                        MessageBox.Show("Invalid Username/Password!");
                    }
            }
        }

        private void button_reset_Click(object sender, EventArgs e)
        {
            txtusername.Text = "";
            txtpwd.Text = "";
        }
        private void txtusername_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtpwd_TextChanged(object sender, EventArgs e)
        {
           
        }

        
        
    }
}
Posted
Updated 13-Feb-12 3:34am
v2

1 solution

Why not make use of the .NET built in membership providers. There are plenty of examples on here and on the web.

Below is a link to one example

http://www.4guysfromrolla.com/articles/120705-1.aspx[^]
 
Share this answer
 
Comments
IviKAZAZI 13-Feb-12 10:12am    
i am not using asp.net

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900