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

  • SEARCH
  • Home
  • 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

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I need to clean up various Word 'smart' characters in user input, including but
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

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.