根据VIEWSTATE所存值判断字符串是否为明文或暗文

if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Display the checkbox when the config name is password.
            var tbConfigName = (TextBox) e.Row.Cells[0].Controls[1];
            var tbConfigValue = (TextBox)e.Row.Cells[1].Controls[1];
            var cbEncrypted = (CheckBox) e.Row.Cells[2].Controls[1];
            //tbConfigName.Attributes.Add("onchange", string.Format("ValueChanged('{0}','{1}');",
                                                                  //tbConfigName.UniqueID, cbEncrypted.UniqueID));
            //string imgPath = this.ResolveUrl("~/images/padlock.jpg");
            //cbEncrypted.Text = "<img src='" + imgPath + "' alt='' />";
            //cbEncrypted.Attributes.Add("onclick", string.Format("CheckedChanged('{0}','{1}');",
            //                                                  tbConfigValue.UniqueID, cbEncrypted.UniqueID));
            //cbEncrypted.Style.Add("display","none");
       
            
            if (tbConfigName.Text.ToLower().Equals("password"))
            {
                // Display the checkbox when the config name is password.
                //cbEncrypted.Style.Add("display", "block");
                if(ViewState["password"]!=null&&!string.IsNullOrEmpty(ViewState["password"].ToString()))
                {
                    //Display the password in password mode if encrypted otherwise in textmode
                    string[] pwdArray = ViewState["password"].ToString().Split('#');
                    cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
                    tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
                                                 ? TextBoxMode.Password
                                                 : TextBoxMode.SingleLine;
                    tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
                                                              ? GetDecryptedPassword(pwdArray[1])
                                                              : pwdArray[1]);
                    //ViewState.Remove("password");
                }
            }

            if (tbConfigName.Text.ToLower().Equals("host"))
            {
                // Display the checkbox when the config name is password.
                //cbEncrypted.Style.Add("display", "block");
                if (ViewState["host"] != null && !string.IsNullOrEmpty(ViewState["host"].ToString()))
                {
                    //Display the password in password mode if encrypted otherwise in textmode
                    string[] pwdArray = ViewState["host"].ToString().Split('#');
                    cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
                    tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
                                                 ? TextBoxMode.Password
                                                 : TextBoxMode.SingleLine;
                    tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
                                                              ? GetDecryptedPassword(pwdArray[1])
                                                              : pwdArray[1]);
                    //ViewState.Remove("host");
                }
            }

            if (tbConfigName.Text.ToLower().Equals("servicesurl"))
            {
                // Display the checkbox when the config name is password.
                //cbEncrypted.Style.Add("display", "block");
                if (ViewState["servicesUrl"] != null && !string.IsNullOrEmpty(ViewState["servicesUrl"].ToString()))
                {
                    //Display the password in password mode if encrypted otherwise in textmode
                    string[] pwdArray = ViewState["servicesUrl"].ToString().Split('#');
                    cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
                    tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
                                                 ? TextBoxMode.Password
                                                 : TextBoxMode.SingleLine;
                    tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
                                                              ? GetDecryptedPassword(pwdArray[1])
                                                              : pwdArray[1]);
                    //ViewState.Remove("servicesUrl");
                }
            }

            if (tbConfigName.Text.ToLower().Equals("pollingobject"))
            {
                // Display the checkbox when the config name is password.
                //cbEncrypted.Style.Add("display", "block");
                if (ViewState["PollingObject"] != null && !string.IsNullOrEmpty(ViewState["PollingObject"].ToString()))
                {
                    //Display the password in password mode if encrypted otherwise in textmode
                    string[] pwdArray = ViewState["PollingObject"].ToString().Split('#');
                    cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
                    tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
                                                 ? TextBoxMode.Password
                                                 : TextBoxMode.SingleLine;
                    tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
                                                              ? GetDecryptedPassword(pwdArray[1])
                                                              : pwdArray[1]);
                    //ViewState.Remove("PollingObject");
                }
            }

            if (tbConfigName.Text.ToLower().Equals("debug"))
            {
                // Display the checkbox when the config name is debug.
                //cbEncrypted.Style.Add("display", "block");
                if (ViewState["debug"] != null && !string.IsNullOrEmpty(ViewState["debug"].ToString()))
                {
                    //Display the password in password mode if encrypted otherwise in textmode
                    string[] pwdArray = ViewState["debug"].ToString().Split('#');
                    cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
                    tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
                                                 ? TextBoxMode.Password
                                                 : TextBoxMode.SingleLine;
                    tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
                                                              ? GetDecryptedPassword(pwdArray[1])
                                                              : pwdArray[1]);
                    //ViewState.Remove("debug");
                }
            }

            if (tbConfigName.Text.ToLower().Equals("version"))
            {
                // Display the checkbox when the config name is version.
                //cbEncrypted.Style.Add("display", "block");
                if (ViewState["version"] != null && !string.IsNullOrEmpty(ViewState["version"].ToString()))
                {
                    //Display the password in password mode if encrypted otherwise in textmode
                    string[] pwdArray = ViewState["version"].ToString().Split('#');
                    cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
                    tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
                                                 ? TextBoxMode.Password
                                                 : TextBoxMode.SingleLine;
                    tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
                                                              ? GetDecryptedPassword(pwdArray[1])
                                                              : pwdArray[1]);
                    //ViewState.Remove("version");
                }
            }


            if (tbConfigName.Text.ToLower().Equals("username"))
            {
                // Display the checkbox when the config name is version.
                //cbEncrypted.Style.Add("display", "block");
                if (ViewState["username"] != null && !string.IsNullOrEmpty(ViewState["username"].ToString()))
                {
                    //Display the password in password mode if encrypted otherwise in textmode
                    string[] pwdArray = ViewState["username"].ToString().Split('#');
                    cbEncrypted.Checked = pwdArray[0].ToLower().Equals("true") ? true : false;
                    tbConfigValue.TextMode = pwdArray[0].ToLower().Equals("true")
                                                 ? TextBoxMode.Password
                                                 : TextBoxMode.SingleLine;
                    tbConfigValue.Attributes.Add("value", pwdArray[0].ToLower().Equals("true")
                                                              ? GetDecryptedPassword(pwdArray[1])
                                                              : pwdArray[1]);
                    //ViewState.Remove("username");
                }
            }


加密方法

   private static string GetDecryptedPassword(string encryptedPassword)
    {
        var passwordBuilder = new PasswordBuilder(new MD5Encryption());
        return passwordBuilder.GetDecryptedPassword(encryptedPassword, new FileCertificateProvider());
    }   


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值