MD5加密,Parameters防止SQL注入:
protected void btnLog_Click(object sender, EventArgs e)
{
//获取验证码
string code = txtCode.Text;
//判断用户输入的验证码是否正确
if (Request.Cookies["CheckCode"].Value == code)
{
//创建数据库连接
SqlConnection con = new SqlConnection("server=.;database=db_Register;uid=sa;pwd=102545;");
//打开数据库连接
con.Open();
//使用MD5加密将用户输入的密码加密
string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtUserpass.Text, "MD5");
//创建SQL语句,该语句用来查询用户输入的用户名和密码是否正确
string sqlSel = "select count(*) from tb_userInfo where userName=@name and userPass=@pass";
//创建SqlCommand对象
SqlCommand com = new SqlCommand(sqlSel, con);
//使用Parameters的add方法添加参数类型,防止SQL注入,Parameters属性传参的方法将非法字符过滤掉.
com.Parameters.Add(new SqlParameter("name", SqlDbType.VarChar, 20));
//设置Parameters的参数值
com.Parameters["name"].Value = txtUserName.Text;
com.Parameters.Add(new SqlParameter("pass", SqlDbType.VarChar, 50));
com.Parameters["pass"].Value = pass;
//判断ExecuteScalar方法返回的参数是否大于0大于表示登录成功并给出提示
if (Convert.ToInt32(com.ExecuteScalar()) > 0)
{
RegisterStartupScript("", "<script>alert('登录成功!')</script>");
//清空文本框
txtCode.Text = txtUserName.Text = "";
}
else
{
RegisterStartupScript("", "<script>alert('用户名或密码错误!')</script>");
}
}
else
{
RegisterStartupScript("", "<script>alert('验证码输入错误!')</script>");
}
}
设置密码强度:
function passHint()
{
var txt=document.getElementById('txtPass').value;
if(txt.length<6)
{
document.all("tab").rows[0].cells[1].bgColor="red";
document.all("tab").rows[0].cells[2].bgColor="";
}else
{
document.all("tab").rows[0].cells[2].bgColor="red";
document.all("tab").rows[0].cells[1].bgColor="";
}
}
<table id="tab" border="0" cellpadding="0" cellspacing="0" style="width: 182px">
<tr>
<td style="width: 276px">
<span style="font-size: 10pt">密码强度:</span></td>
<td id="r" style="width: 100px">
<asp:Label ID="labEbb" runat="server" Text="弱" Width="18px" Font-Size="12px"></asp:Label></td>
<td style="width: 92px">
<asp:Label ID="labStrong" runat="server" Text="强" Width="18px" Font-Size="12px"></asp:Label></td>
<td style="width: 106px">
</td>
</tr>
</table>
判断是否注册:
前台代码:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="width: 477px; height: 48px;">
<tr>
<td style="width: 88px; height: 24px; text-align: right">
<span style="font-size: 10pt">会 员 名: </span>
</td>
<td style="height: 24px; text-align: left; width: 509px;" colspan="2">
<asp:TextBox onFocus="tName();" ID="txtName" runat="server" Width="89px" AutoPostBack="True"
OnTextChanged="txtName_TextChanged"></asp:TextBox><span style="color: #ff0000">*</span><asp:RequiredFieldValidator
ID="rfvName" runat="server" ErrorMessage="用户名不能为空" Width="1px"
ControlToValidate="txtName">*</asp:RequiredFieldValidator>
<asp:Label ID="labUser" runat="server" Text="只能输入数字、字母、下划线" Width="159px" Font-Size="12px"></asp:Label>
<asp:Label ID="labIsName" runat="server" Font-Size="12px"></asp:Label></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
后台代码:
protected bool isName()
{
//创建一个布尔型变量并初始化为false;
bool blIsName = false;
//创建SQL语句,该语句用来判断用户名是否存在
string sqlSel = "select count(*) from tb_userInfo where userName='" + txtName.Text + "' ";
//创建数据库连接
SqlConnection con = new SqlConnection("server=.;database=db_Register;uid=sa;pwd=102545;");
//打开数据库连接
con.Open();
//创建SqlCommand对象
SqlCommand com = new SqlCommand(sqlSel, con);
//判断ExecuteScalar方法返回的参数是否大于0,大于表示用户名已存在
if (Convert.ToInt32(com.ExecuteScalar()) > 0)
{
blIsName = true;
}
else
{
blIsName = false;
}
//返回布尔值变量
return blIsName;
}
protected bool isNameFormar()
{
//创建一个布尔型变量并初始化为false;
bool blNameFormar = false;
//设置正则表达式
Regex re = new Regex("^\\w+$");
//使用Regex对象中的IsMatch方法判断用户名是否满足正则表达式
if (re.IsMatch(txtName.Text))
{
//设置布尔变量为true
blNameFormar = true;
//设置label控件的颜色
labUser.ForeColor = System.Drawing.Color.Black;
}
else
{
labUser.ForeColor = System.Drawing.Color.Red;
blNameFormar = false;
}
//返回布尔型变量
return blNameFormar;
}
protected void txtName_TextChanged(object sender, EventArgs e)
{
//判断用户名是否为空
if (txtName.Text == "")
{
//使用Label控件给出提示
labIsName.Text = "用户名不能为空";
//设置Label控件的颜色
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
//调用自定义isNameFormar方法判断用户名是否满足格式要求
if (isNameFormar())
{
//调用isName自定义方法判断用户名是否已注册
if (isName())
{
labIsName.Text = "用户名已存在!";
labIsName.ForeColor = System.Drawing.Color.Red;
}
else
{
labIsName.Text = "可以注册!";
labIsName.ForeColor = System.Drawing.Color.Blue;
}
}
else
{
labIsName.Text = "";
}
}
}
- ASP.NET使用jQuery AJAX实现MD5加密实例
一个asp.net ajax例子,使用jquery,实现md5加密.在.NET 4.0,Visual Studio 2010上成功运行. 效果体验:http://tool.keleyi.com/t/m ...
- ASP.NET MVC 5使用Filter过滤Action参数防止sql注入,让你代码安全简洁
在开发程序的过程中,稍微不注意就会隐含有sql注入的危险.今天我就来说下,ASP.NET mvc 5使用Filter过滤Action参数防止sql注入,让你代码安全简洁.不用每下地方对参数的值都进行检 ...
- SpringSecurity 登录 - 以及Md5加密
我们现在开放一个链接给其他系统,来访问我们的系统 http://localhost:8080/hulk-teller-web/haihui!init.jspa?loginId=teller01& ...
- django简单实现注册登录模块
源码下载:https://files.cnblogs.com/files/hardykay/login.zip 新建项目(我使用pycharm开发,也可以使用如下命令建立项目 ) cmd命令行,前提需 ...
- 从微信小程序到鸿蒙js开发【08】——表单组件&注册登录模块
目录: 1.登录模块 2.注册模块 3.系列文章导读 牛年将至,祝大家行行无bug,页页so easy- 在微信小程序中,提供了form组件,可以将input.picker.slider.button ...
- hash模块MD5加密
MD5加密:获取32位加密字符串: 示例(MD5加密'123456')import hashlibhashObject=hashlib.md5(b'123456') #实例化,加密字符串不能直接加密, ...
- nodejs 用户登录密码md5加密
jade文件 div.login ul.inp-content li span= '用户名:' input.ui-input1#input1(placeholder='请输入手机号') li sp ...
- python hashlib模块 md5加密 sha256加密 sha1加密 sha512加密 sha384加密 MD5加盐
python hashlib模块 hashlib hashlib主要提供字符加密功能,将md5和sha模块整合到了一起,支持md5,sha1, sha224, sha256, sha384, ...
- 关于Django auth注册登录模块的具体使用
from django.urls import path from . import views urlpatterns = [ #主页,用来显示类别等其他数据 path('',views.index ...
随机推荐
- HW7.7
public class Solution { public static void main(String[] args) { double[][] points = { {-1, 0, 3}, { ...
- CentOS 6.5 安装配置
关于CentOS的安装,网上有很多详细的教程.其实重点就在于硬盘的分区和软件的定制这两块.下面我在VirtualBox虚拟机上安装 CentOS-6.5-i386-minimal. 1.在起始菜单处选 ...
- Android问题-DelphiXE5编义时提示找不到“连接器(arm-linux-androideabi-ld.exe)"
问题现象:DelphiXE5编义时提示找不到“连接器(arm-linux-androideabi-ld.exe)" 问题提示:Checking project dependencies... ...
- 按要求编写一个Java应用程序: (1)定义一个类,描述一个矩形,包含有长、宽两种属性,和计算面积方法。 (2)编写一个类,继承自矩形类,同时该类描述长方体,具有长、宽、高属性, 和计算体积的方法。 (3)编写一个测试类,对以上两个类进行测试,创建一个长方体,定义其长、 宽、高,输出其底面积和体积。
package jvxing; public class Jvxing { //成员变量 private double width; private double chang; public doub ...
- Unity3d 使用NPOI读写Excel 遇到的问题
开发环境:unity5.3 NPOI(.net 2.0版 http://npoi.codeplex.com/) 运行环境:PC版, 其他平台没有测试 先上效果图: 实现步骤: 1.新建一个Exce ...
- 【转】phpmyadmin万能密码漏洞
影响版本:2.11.3 / 2.11.4 利用方法:用户名处写入‘localhost’@'@”则登录成功. (注意全部是英文标点符号,最后一个为英文双引号) 附上几个php爆绝对路径的办法: phpM ...
- 导出cluster log
将所有群集节点的日志导出到 clog 目录下: get-clusterlog -destination c:\clog 只导出前10分钟的群集日志: get-cluster -destination ...
- C#-获取datagriview选中行中某一列的值
获取选中行中某一列的值: int index = dg_Product.CurrentRow.Index; //取得选中行的索引 txt_ProductId.Text = dg_Product.Row ...
- 安装完zend server后,无法访问http://localhost:10081/ZendServer/的解决办法
安装完ZendServer后,默认会设置http://localhost:10081/ZendServer/为ZendServer的后台管理页面, 但对于ZendServer5.0.2(其它版本未知) ...
- js 数组排序要注意的问题,返回的值最好为 -1, 0, 1之间的值
var test10Elements = [7, 6, 5, 4, 3, 2, 1, 0, 8, 9]; var comparefn = function (x, y) { return x - y; ...