目前我有一个网站,上面有一个简单的 html 注册表单,代码如下:
<div class="grid_6 push_3 block alpha">
<div class="grid_6 form_block alpha omega">
<label>שם משתמש</label>
</div>
<div class="grid_6 form_block alpha omega">
<input type="text" id="username" name="username" pattern="^\S{4,}$" required />
</div>
<div class="grid_6 alpha omega form_block">
<label>סיסמא</label>
</div>
<div class="grid_6 form_block alpha omega">
<input type="password" id="password" name="password" pattern="^\S{6,}$" required title="סיסמא צריכה להכיל לפחות 6 תווים" />
</div>
<div class="grid_6 alpha omega form_block">
<label>וודא סיסמא</label>
</div>
<div class="grid_6 form_block alpha omega">
<input type="password" id="password2" pattern="^\S{6,}$" required />
</div>
<div class="grid_6 alpha omega form_block">
<label>כתובת אימייל</label>
</div>
<div class="grid_6 form_block alpha omega">
<input id="email" name="email" type="email" required pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" />
</div>
<div class="grid_6 alpha omega form_block">
<label>וודא כתובת אימייל</label>
</div>
<div class="grid_6 form_block alpha omega">
<input type="email" id="email2" required pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" />
</div>
<div class="grid_6 form_block alpha omega">
<input name="submit" type="submit" onclick="return validateForm()" value="שלח" />
</div>
</div>
(它实际上被包含在母版页的标签中,这是母版:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="css/reset.css" rel="stylesheet" />
<link href="css/text.css" rel="stylesheet" />
<link href="css/963_9_10_10.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body dir="rtl">
<form runat="server">
<div class="container_9">
<div class="header grid_9">
<a href="Default.aspx"><h1>סיכומים.נט</h1></a>
</div>
<!-- END HEADER -->
<nav>
<ul class="clearfix grid_6 push_3">
<a href="literature.aspx"> <li class="grid_1 alpha literature">ספרות</li></a>
<a href="language.aspx"> <li class="grid_1 language">לשון</li></a>
<a href="civics.aspx"><li class="grid_1 civics">אזרחות</li></a>
<a href="history.aspx"><li class="grid_1 history">היסטוריה</li></a>
<a href="bible.aspx"> <li class="grid_1 bible">תנך</li></a>
<a href="english.aspx"> <li class="grid_1 omega english">אנגלית</li></a>
</ul>
</nav>
<div class="grid_3 pull_6" id="search">
<input type="text" id="search_box" placeholder="הקלד מילות חיפוש"/>
<input type="submit" value="חפש" id="search_button"/>
</div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<footer class="grid_9">
2013 © כל הזכויות שמורות לסיכומים.נט
</footer>
</div>
<!-- END CONTAINER -->
</form>
</body>
</html>
我还有一个 signup.aspx.cs 文件,它将注册信息插入到数据库中,如下所示:
public partial class signup : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["submit"] != null) {
register1();
}
}
public void register1()
{
string sql = "INSERT INTO [userinfo] ([username], [password], [email]) VALUES (N'" + Request.Form["username"] + "', N'" + Request.Form["password"] + "', N'" + Request.Form["email"] + "')";
Database.UpdateData(sql);
}
}
我认为到目前为止我所做的一切都是正确的(我是 html/css 之外的任何东西的初学者),但如果我犯了任何错误,请纠正我。
我现在要做的是在将表单输入服务器端插入数据库之前验证它。我想检查它是否符合我的所有规则、字符长度、匹配字段等 - 并且还没有使用用户名/电子邮件。
我目前正在做一些基本的 javascript 验证,但我知道这还不够安全。
关于我现在必须做什么的解释(尽可能简单)会很棒。理想情况下,我想返回注册页面并以可自定义的方式在表单顶部列出错误。
谢谢