如何更新密码并将当前密码的记录保存在另一个表中 [英] How to update password and keep the record of current password in another table

查看:104
本文介绍了如何更新密码并将当前密码的记录保存在另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dot net中使用c#和LINQ以及SQL服务器作为数据库

我有三个表s_reg,s_log,s_pass

s_reg有reg_id主键,s_log将log_id和reg_id作为主键和外键,s_pass将pass_id和log_id作为主键和外键

我想在s_reg中更新ID的密码并将旧密码保存在s_pass表中还使用reg_id在s_log表中更新新密码

i已在s_reg中更新了密码列,但它只接受reg_id(因为它是自动增量)和新密码而不是旧密码并将剩余字段显示为NULL

也在s_log和s_pass表中发生了变化,但两者都不接受reg_id,reg_id列显示为NULL或0



< b>我尝试了什么:



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


var check =(来自ps.s_regs中的m
在m.reg_id上的ps.s_logs中的连接等于s.reg_id
其中s.susnm == TextBox1.Text&& ; s.spass == TextBox2.Text
选择新的{s,m})。FirstOrDefault();
if(check!= null)
{
try
{
s_log log = new s_log();
使用(studentDataContext database = new studentDataContext())//更新列
{
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>);
}

其他
{
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 =(来自于ps.s_passes中的m
在m.reg_id上的ps.s_regs中加入n等于n.reg_id
选择新的{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 =(来自ors in ps.s_logs
join trd in ps.s_regs
on ord.reg_id equals trd.reg_id
where trd.susnm == TextBox1.Text
选择新的{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);
}
}
}


其他
{
ScriptManager.RegisterStartupScript(Page,Page.GetType(), str,alert('请检查用户名和密码');,true);
}

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

解决方案

Don'这样做!切勿以明文形式存储密码 - 这是一个主要的安全风险。有关如何在此处执行此操作的信息:密码存储:如何做到这一点。 [ ^ ]

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);
               }
           }
       }
   }

解决方案

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.[^]


这篇关于如何更新密码并将当前密码的记录保存在另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆