Click here to Skip to main content
15,885,216 members

Comments by Member 10248768 (Top 42 by date)

Member 10248768 18-Aug-14 6:14am View    
Dear NeoMayank
Thank you for replying to my query/question on such short notice. I know how to create parametrized constructor of login form(frmLogin). But i am just wondering on how to assign value of variable:mid from login form which contains manager_id of currently logged in manager of application to field:created_by in table:UserDetail2 through form(frmUser) in c# windows forms with sql server 2008? Can you show me a sample on how it needs to be done? I hope you are not annoyed with my reply! Reply please!? I hope i get reply from you Sir!
Member 10248768 23-Jul-14 8:06am View    
You are correct i will write pseudo code for that and will ask you sir.
Member 10248768 22-Jul-14 0:02am View    
Dear RyanDev and j snooze
the value of user type of normal user:0 and value user type of manager:1 in my table:UserDetail in sql server 2008.
Given below is my c# code of frmLogin(login form) which i have created:

using System.Data.SqlClient;
namespace Mini_Project
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
if ((txtPassword.Text == "password") && (txtUsername.Text.ToLower() == "admin"))
{
MDIParent1 h = new MDIParent1();
h.Show();
this.Close();
}
else
{
string username = txtUsername.Text;
string password = txtPassword.Text;
bool validUser = ValidateUser(username, password);
if (validUser)
{
MDIParent1 m = new MDIParent1();
m.Show();
this.Close();
}
else
{
MessageBox.Show("Invalid user name or password. Please try with another user name or password", "Task", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtUsername.Focus();
}
}
}
private bool ValidateUser(string username, string password)
{
bool success = false;
SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Task;Integrated Security=true");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd = new SqlCommand("Select @count = Count(*) from [dbo].[UserDetail] where username=@username and password=@password", conn);
cmd.Parameters.AddWithValue("@username", txtUsername.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
cmd.Parameters.Add("@count", SqlDbType.Int).Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
if (Convert.ToInt32(cmd.Parameters["@count"].Value) > 0)
{
success = true;
}
else
{
success = false;
}
conn.Close();
return success;
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}

The above code works OK! but not the way i want.
What i want is when a normal user of user_type:0 logs into the application then i want addManagerToolStripMenuItem and addUserToolStripMenuItem should be disabled for that user when he enters into the application.

When an manager user of user_type:1 logins into the application then i want addUserToolStripMenuItem only should be enabled for that user when he enters into the application.
So tell me what modifications of c# code must i do and where to achieve my required result?! Reply please! I am waiting for your reply! I hope i get a reply !
Member 10248768 17-Jul-14 1:11am View    
Dear CPallini
I think that your code should do the trick! But can you show/send me sample on how to add a field(failure_count) to user table which increments upon each failure login and resets it to 0 upon each successful login from c# windows forms?

Given below is my structure of my table named:user in sql server 2008:

ColumnName DataType AllowNulls
user_first_name nvarchar(50) Yes
user_last_name nvarchar(50) Yes
username nvarchar(30) Yes
user_id(auto-increment) Int No
password nvarchar(15) Yes
user_dob date Yes
user_sex nvarchar(20) Yes
email nvarchar(50) Yes
user_type Int Yes
row_upd_date datetime Yes
created_by smallint Yes

Can you guide me/help me on how to add and implement failure_count field in table user which increments by 1 upon each failure login and resets to 0 upon successful login from c# windows forms? Reply Please?! I hope i get a reply from You!
Member 10248768 17-Jul-14 0:21am View    
Dear Member10950750
Thank you for replying to my question/query on such short notice.
However i cannot understand what you mean by "saving the "hitcount" in database from "else" block in order to check the hitcount on behalf of username and password to restrict his login when that particular user tries to login again after 3 failed attempts"? Should i need to include hitcount as a field in my table named:User in sql server 2008? If so tell me how to increment hitcount on each failure login of that user until 3 and reset it to 0 on successful login? Can explain it to little briefly because i cant understand what you are trying to say? Reply Please Sir?! I am waiting for your reply! I hope i get a reply from you Sir!