Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:48:11+00:00 2026-05-11T05:48:11+00:00

I’m trying to work out how to validate a user in my application but

  • 0

I’m trying to work out how to validate a user in my application but i don’t know how. I wish create a form with Username and Password to enter in the application(WPF) using Linq toSql to store and validate Username and password in the database but i don’t know so much about Linq to Sql so i keep in stuck now. I have a database with this fields’UserID,UserTypeID,Name,Surname,Username,Password,Email’ and here there is the code that i use :

public Window1()     {         InitializeComponent();      }      public bool ValidateApplicationUser(string userName, string password)     {         bool validUser = false;         try         {          //   var conn = 'Data Source=MAMMA-PC/SQLMAMMA;Initial Catalog=MyWebSite;Integrated Security=True';             DataClasses1DataContext dc = new DataClasses1DataContext();             Table<User> users = dc.GetTable<User>();              var query = from c in dc.Users                         where (c.Username == userName.ToLower() && c.Password == password.ToLower())                         select c;              validUser = (query != null);          }         catch (Exception ex)         {             if (ex != null)             {             }         }          return validUser;     }      private void mahhh(object sender, RoutedEventArgs e)     {            bool authenticated = true;      //   var conn = 'Data Source=MAMMA-PC/SQLMAMMA;Initial Catalog=MyWebSite;Integrated Security=True';             DataClasses1DataContext dc = new DataClasses1DataContext();             Table<User> users = dc.GetTable<User>();              var query = from c in dc.Users                         where (c.Username == usernameTextBox.Text.ToString() && c.Password == passwordTextBox.Text.ToString())                         select c;        /*      foreach (User user in query)             {                 user.Username = usernameTextBox.Text.Trim();                 user.Password = passwordTextBox.Text.Trim();             } */           {             if (usernameTextBox.Text !='' && passwordTextBox.Text != '')             {                 authenticated = ValidateApplicationUser(usernameTextBox.Text , passwordTextBox.Text);             }          }         if (!authenticated)         {             MessageBox.Show('Invalid login. Try again.');         }         else         {             MessageBox.Show('Congradulations! You're a valid user!');       //        Window2 c = new Window2();     //        c.ShowDialog();             this.Close();         }      } 

When i insert the password and username the form validate also wrong username and password so i receive always the message ‘Congradulations! You’re a valid user!’!!!

DO you have any advice where i wrong?

Bye

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:48:12+00:00Added an answer on May 11, 2026 at 5:48 am

    Firstly its a best practice to Hash Passwords(one way encryption) with a Salt (random string you tag on the end of your password), I know it sounds complex but it isn’t.

    It isn’t a good practice to wrap everything around with try, unless you are

    The Linq Code Would Be

    public bool ValidateApplicationUser(string userName, string password) {     //Get Database Context     var AuthContext = new DataClasses1DataContext();      //We Are Only Going To Select UserId, Notice The Password .ToLower Is Removed (for security)     var query = from c in AuthContext.Users                 where (c.Username == userName.ToLower() && c.Password == password)                 select c;      if (query.Count() != 0) {        return true;     }      return false; } 

    Salt Could Be Done Using Database Or C#

    http://blog.stevex.net/index.php/c-code-snippet-creating-an-md5-hash-string/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 131k
  • Answers 131k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As it turns out, Java2D (which I'm assuming is what… May 12, 2026 at 6:15 am
  • Editorial Team
    Editorial Team added an answer gbn, I think you meant to write DECLARE @value INT… May 12, 2026 at 6:15 am
  • Editorial Team
    Editorial Team added an answer tf undo $/ /r tfpt online /adds /deletes /diff /noprompt… May 12, 2026 at 6:15 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.