Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.25/5 (4 votes)
See more:
hi there ,
i have a simple login form using C#2008 And Sqlserver 2008 ,and it work very nice but the question is i need when the user Enter the password 3 time wrongly(if he forget or someone else try to enter his account) ,the account is blocked and in the same time the webcam take an image for the person in that computer and save it in sql table
i want to know can i do that!!! , if i can please give me the way to do it or simple code to add it in my login form
and this my login code :


C#
1	        private bool CompareStrings(string string1, string string2)  
2	        {  
3	            return String.Compare(string1, string2, true, System.Globalization.CultureInfo.InvariantCulture) == 0 ? true : false;  
4	        }  
5	 
6	        private void button1_Click(object sender, System.EventArgs e)  
7	        {  
8	            try 
9	            {  
10	                SqlConnection con = new SqlConnection();  
11	                con.ConnectionString = "Server=.\\SQLEXPRESS; Database=Sample; User Id=sa; password=sa123";  
12	                UGIcon.Open();  
13	 
14	                SqlCommand cmd = new SqlCommand("SELECT ISNULL(stUsername, '') AS stUsername, ISNULL(stPassword,'') AS stPassword, ISNULL(stRole,'') AS stRole FROM LoginDetails WHERE stUsername='" + textBoxUsername.Text + "' and stPassword='" + textBoxPassword.Text + "'", con);  
15	 
16	                SqlDataReader dr = cmd.ExecuteReader();  
17	 
18	                string userText = textBoxUsername.Text;  
19	                string passText = textBoxPassword.Text;  
20	                string stRole = "admin";  
21	 
22	                while (dr.Read())  
23	                {  
24	                    if (this.CompareStrings(dr["stUsername"].ToString(), userText) &&   
25	                        this.CompareStrings(dr["stPassword"].ToString(), passText) &&   
26	                        this.CompareStrings(dr["stRole"].ToString(), stRole))  
27	                    {  
28	                        MessageBox.Show("OK");  
29	                    }  
30	                    else 
31	                    {  
32	                        MessageBox.Show("Error");  
33	                    }  
34	 
35	                }  
36	 
37	                dr.Close();  
38	 
39	                con.Close();  
40	 
41	            }  
42	            catch(Exception ex)  
43	            {  
44	                MessageBox.Show(ex.Message);  
45	            }  
46	        } 



thanx in advance
Posted
Comments
Sergey Alexandrovich Kryukov 31-Oct-12 14:45pm    
And what's the problem? This is not even a question.
--SA
Dave Kreskowiak 31-Oct-12 15:48pm    
WHY would you want to do that?? If the person is legit and fogot their password, they're not going to want their picture taken.

Also, what if the laptop is running, but the lid is closed?? My machine right now sits next to me with the lid closed (the cam is also disabled by policy) and on runs my two 24" monitors. Good luck getting a picture like that.

This is a feature that really doesn't do you much good at all.
Munirajant 1-Nov-12 1:08am    
Hi Its a Good attempt ...working on your query... if i got d right one...will post a solution
rawa1990 4-Nov-12 13:27pm    
ok thank's i will wait

1 solution

Hi
Add this above line 1
C#
int LoginAttempts=0;

Then add this at line 32:
C#
LoginAttempts=LoginAttempts+1;
if (LoginAttempts<=3)
{
//Insert capture code here
}


Look at this guy's webcam controls. If even has face following. https://sites.google.com/site/webcamlibrarydotnet/winfrom-and-csharp-sample-code-and-download[^] Add the save command in the capture image method & use this libary to save the image: http://imageresizing.net/download[^]
I don't know how to save an image directly to a SQL table but I would save it in a directory & save the path in SQL.

Hope this helps

Jacques
 
Share this answer
 
Comments
rawa1990 4-Nov-12 13:15pm    
Thank you very much Jacques

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900