[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how can i create security class for my C#.net window application ?

Posted on 2011-02-17
4
Medium Priority
?
394 Views
Last Modified: 2012-05-11
i want to create security class for my window application , when i start application it will prompt for the password and if user give correct password then he/she login in to application,
otherwise can't login and set other parameter also ,
but how can i do this ?
0
Comment
Question by:Parth48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 34914530
It's all depending of your requirement. Take a look at the following:

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22549287.html
0
 
LVL 12

Expert Comment

by:Praveen Kumar
ID: 34914677
Basically you need to implement a Login form.



string username = txtUserName.Text;
string password = txtPassword.Text;

if (ValidateUserNamePassword(username, password))
{
    // move to next form or do whatever you need to do after a successfull login
}
else
{
    MessageBox.Show("Invalid user name or password", "Invalid Login");
    return;
}


public bool ValidateUserNamePassword(string _username, string _password)
{
       string connectionString = "Data Source=[servername];Initial Catalog=[databaseName];User ID=[Admin Login];Password=[Admin Password];";

       using (SqlConnection cn = new SqlConnection(connectionString);
       {
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = cn;
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.CommandText = "tsp_GetUserNameAndPassword";

          SqlParameterCollection sqlParams = cmd.Parameters;
          sqlParams.AddWithValue("@UserName", _username);
          sqlParams.AddWithValue("@Password", _password);

          cn.Open();
          SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
          if (dr.Read())
          {
                // this will return true if a row matching the username and password is found.
                // this means that the user's input is valid
                return true;
          }
          else
          {
                return false;
           }

          dr.close();
          cn.close();
       }
}
0
 
LVL 8

Expert Comment

by:cubaman_24
ID: 34924886
Hello:
Don't re-invent the wheel. Use Integrated security or Aspnet memebership. It'll save you a lot of time and troubles. Notice that you can use Aspnet membership system in windows applications too.

http://msdn.microsoft.com/en-us/library/yh26yfzy.aspx

Best regards
0
 
LVL 1

Accepted Solution

by:
diwakarverma earned 2000 total points
ID: 34926266
Why you need separate class for logon if you just need to validate user. You can use previous post to just validate user name and password on okay button click of logon dialog.

If you looking for similar feature about how window based authentication woks on ASP.net then you need to implement client application services (please refer http://msdn.microsoft.com/en-us/library/bb384297.aspx for more information).

If you just looking for business class that does authentication then you may go for singleton class like:

Class Logon
{
      Private Logon _logonUser = null;
      Private Logon() {}
      Public GetLoggedOnUser()
      {
            Lock {
                  If (_logonUser == null)      _logonUser  = new Logon();
                  }
            Return _logonUser;
      }
      Public bool LogonUser(string username, string password)
      { // Authenticate User here }
      Public bool LogoutUser()
      {
            // Do some more log off operations
_logonUser = null;
}

The other benefit of having such class that you can have logger (trace info) specified in this class and many others
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question