0

I need to know about how to check the entered password and User_ID is correct from my table created in SQL Server 2012.

Kindly give me a link or code if anybody knows about it from beginning like making connection string and so on ...... !

Thanks in advance to all programmers :P

5
  • Have a look at this msdn.microsoft.com/en-us/library/mt715492.aspx Commented Apr 22, 2017 at 20:06
  • yeah but this is not my answer according to my question ..... just need a simple code to check that ID and password is in my table or not to move on next screen .... Commented Apr 22, 2017 at 21:05
  • in the article shown how to connect to database and execute queries. if you connected to your database, then there should not be any problem to just execute needed query and user credentials. Or you can use simple SqlConnection and SqlCommand to execute yout query. Here is example msdn.microsoft.com/en-us/library/fksx3b4f.aspx Commented Apr 22, 2017 at 21:10
  • Thanks @Ruben i hope it will work for me also .... :) Commented Apr 22, 2017 at 21:19
  • You could also look into implementing Entity Framework. EF makes it very simple to query a database, without having to deal with any SqlConnections or SqlCommands. The link is a beginners guide to setting up EF from an existing database. msdn.microsoft.com/en-us/library/jj200620(v=vs.113).aspx Commented Apr 23, 2017 at 2:44

2 Answers 2

2

Implement authentication is a different matter than database programming. You should first focus on core issues one by one.

This is what you actually need :

WPF: Implementing Custom Authentication And Authorization

Optionally,

Entity Framework Code First to an Existing Database

Sign up to request clarification or add additional context in comments.

1 Comment

well I visit the link you post here and its really helpful for me in future but i did my work as I post my answer below...... Thanks alot @anjunskhan
-1

Due to the lack of time I am not going to follow Entity Framework for my application but still I got the answer from this link.

https://msdn.microsoft.com/en-us/library/fksx3b4f.aspx

and here is my code to Check the Entered User_ID and Password is Correct or not ....

    private String ConnectionString;
    private SqlConnection connection;
    private SqlCommand cmd = new SqlCommand();
    private SqlDataReader reader;

    public MainWindow()
    {
        InitializeComponent();

        ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\RFIDdatabase.mdf;Integrated Security=True";
        connection = new SqlConnection(ConnectionString);
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            Console.WriteLine(ID.Text + " and " + Pass.Password);

            cmd.CommandText = "Select * from Login "
                            + "where USER_ID = '" + ID.Text + "' "
                            + "and Password = '" + Pass.Password + "'";

            Console.WriteLine(cmd.CommandText);
            cmd.Connection = connection;
            connection.Open();
            reader = cmd.ExecuteReader();

            int i = 0;

            while (reader.Read())
            {
                i++;
            }


            if (i == 1)
            {
                Window1 win = new Window1();
                win.Show();
            }
            else {
                MessageBox.Show("INCORRECT PASSWORD OR USER ID", "Authentication Failed");
            }

        }
        catch (Exception ex)
        {
            Console.WriteLine("Catch Block = " + ex);
        }
        finally {

            connection.Close();
        }
    }

1 Comment

Your password isn't hatched. Your app has less security than a wide open door.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.