Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working in dot net with c# and LINQ and SQL server as database
I have three tables s_reg,s_log,s_pass
s_reg has reg_id primary key,s_log has log_id and reg_id as primary and foreign key resp.,s_pass has pass_id and log_id as primary and foreign key
I want to update password of a ID in s_reg and keep the old password in the s_pass table and also update new password in s_log table with reg_id
i have updated password column in s_reg but it is only accepting reg_id(as it is on auto increment) and new password instead of old and showing remaining fields as NULL
also changes are taking place in s_log and s_pass tables but both are not accepting reg_id, the reg_id column is showing either NULL or 0

What I have tried:

protected void Button1_Click(object sender, EventArgs e)
   {
       using (studentDataContext ps = new studentDataContext())
       {


           var check = (from m in ps.s_regs
                        join s in ps.s_logs on m.reg_id equals s.reg_id
                        where s.susnm == TextBox1.Text && s.spass == TextBox2.Text
                        select new { s, m }).FirstOrDefault();
           if (check != null)
           {
               try
               {
                   s_log log = new s_log();
                   using (studentDataContext database = new studentDataContext())//update column
                   {
                       var up = ps.s_regs.Where(a => a.spass == TextBox2.Text).FirstOrDefault();
                       if (up != null)
                       {
                           s_reg reg = new s_reg();
                           reg.spass = TextBox2.Text;
                           ps.s_regs.InsertOnSubmit(reg);
                           ps.SubmitChanges();
                           Response.Write("<script>alert('save successfuly');</script>");
                       }

                       else
                       {
                           up.spass = TextBox3.Text;
                           log.reg_id = reg.reg_id;
                           ps.SubmitChanges();
                           Response.Write("<script>alert('Update successfuly');</script>");
                       }

                   }
                   s_pass ureg = new s_pass();

                   var chk = (from m in ps.s_passes
                              join n in ps.s_regs on m.reg_id equals n.reg_id
                              select new { m.ppass, n.sname }).FirstOrDefault();
                   if (chk != null)
                   {
                       try
                       {

                           ureg.pname = TextBox5.Text;
                           ureg.puname = TextBox1.Text;
                           ureg.ppass = TextBox2.Text;
                           ureg.reg_id = reg.reg_id;
                           ps.s_passes.InsertOnSubmit(ureg);
                           ps.SubmitChanges();
                       }
                       catch (Exception ex)
                       {
                           Response.Write("Error:" + ex.Message);
                       }

                       var query = (from ord in ps.s_logs
                                    join trd in ps.s_regs
                                    on ord.reg_id equals trd.reg_id
                                    where trd.susnm == TextBox1.Text
                                    select new { ord, trd }).FirstOrDefault();
                       if (query != null)
                       {
                           try
                           {
                               log.susnm = TextBox1.Text;
                               log.spass = TextBox3.Text;
                               log.reg_id = reg.reg_id;

                               ps.s_logs.InsertOnSubmit(log);
                               ps.SubmitChanges();
                           }

                           catch (Exception ex)
                           {
                               Response.Write("Error:" + ex.Message);
                           }
                       }
                   }


           else
           {
                   ScriptManager.RegisterStartupScript(Page, Page.GetType(), "str", "alert(' please check user name and password ');", true);
               }

           }
               catch (Exception ex)
               {
                   Response.Write("Error:" + ex.Message);
               }
           }
       }
   }
Posted
Updated 26-Apr-18 20:44pm
v2

1 solution

Don't do it like that! Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
 
Share this answer
 
Comments
Richard MacCutchan 27-Apr-18 3:32am    
Maybe he works for TSB.

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