ASP.Net中的加密和解密 [英] Encryption And Decryption in ASP.Net

查看:75
本文介绍了ASP.Net中的加密和解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在我的程序中加密和解密数据库,但我不知道应该从哪里开始。我可以在SubmitPage和登录页面上的解密中加密我的加密代码吗?或者我需要把它放在其他地方吗?



这是提交页面:

I planned to encrypt and decrypt the database in my program but I don''t know where I should start. Can I have my encryption code on the SubmitPage and the Decryption on the login page? Or do I need to put it some where else?

This is the Submit page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;


public partial class SubmitPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
            con.Open();

            string cmdStr = "Select count(*) from TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
            string cmdStr2 = "Select count(*) from TableCEO where EmailAddress ='" + TextBoxEA.Text + "'";
            string cmdStr3 = "Select count(*) from TableIALO where EmailAddress ='" + TextBoxEA.Text + "'";
            SqlCommand userExist = new SqlCommand(cmdStr, con);
            SqlCommand cmd = new SqlCommand("select * from TableSecurity", con);
            SqlCommand cmd2 = new SqlCommand("select * from TableCEO", con);
            SqlCommand cmd3 = new SqlCommand("select * from TableIALO", con);
            int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
            if (temp == 1)

                Response.Write("User Name Already Exist!!!<br /> Please Choose Another User Name.");
        }



    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
        con.Open();

        string chkUser = "select count(*) from TableCEO where EmailAddress'" + TextBoxEA.Text + "";
        chkUser = "select count(*) from TableIALO where EmailAddress'" + TextBoxPW.Text + "";
        SqlCommand chkUsercmd = new SqlCommand(chkUser, con);


        string insCmd = "Insert into TableSecurity (EmailAddress, Password, AccessLevel) values (@EmailAddress, @Password, @AccessLevel)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
        insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
        


        try
        {
            insertUser.ExecuteNonQuery();
            con.Close();
            Response.Redirect("Login.aspx");
        }
        catch (Exception er)
        {
            Response.Write("Something Really Bad Has Happened....Please Try Again.");
        }
        finally
        {
        }
    }
}

推荐答案

有多种方法可以加密或解密数据。我为您提供了一些链接,您可以参考它并找到最适合您的链接。



使用c#加密或解密用户密码

加密或解密密码

使用源代码进行简单的字符串加密和解密

简化的.NET加密



此外,您可以这样做,当用户创建帐户时在数据库中撕掉他的密码'哈希(从单向散列函数生成)。



- 当用户登录时,使用相同的函数将输入的密码转换为哈希您在创建帐户时使用过,比较哈希值并执行相应的操作。
There are number of ways to encrypt or decrypt the data.I am providing you some links you can refer to it and find the one that best suits you.

encrypt or decrypt user password with c#
Encrypt or Decrypt your password
Simple String Encryption and Decryption with Source Code
.NET Encryption Simplified

Further,you can make such that,when user creates account store his password''s hash(generated from one way hash function) in database.

-When user logs in,convert entered password into hash using the same function that you had used at the time of account creation,compare the hash and perform the appropriate action.


这篇关于ASP.Net中的加密和解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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