小弟刚开始学.net,请大家给一些登陆,注册方面的一些思路啊,能提供一些小的代码或程序最好,先谢谢了!

解决方案 »

  1.   

    一样,我也刚学,今天写的一个简单的注册。aspx.cs
    //===================================================================
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace Demo_Database.Manage
    {
    /// <summary>
    /// Summary description for admin_addManage.
    /// </summary>

    public class admin_addManage : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Label Label2;
    protected System.Web.UI.WebControls.Label Label3;
    protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
    protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
    protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
    protected System.Web.UI.WebControls.TextBox username;
    protected System.Web.UI.WebControls.TextBox pass;
    protected System.Web.UI.WebControls.TextBox pass2;
    protected System.Web.UI.WebControls.Button cmdReg;
    protected System.Web.UI.WebControls.Button cmdCancel;
    protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
    protected System.Web.UI.WebControls.Label Label1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
    this.cmdReg.Click += new System.EventHandler(this.cmdReg_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void cmdReg_Click(object sender, System.EventArgs e)
    {
    string uname=this.username.Text;
    string pass=this.pass.Text;
    if (checkUser(uname))
    {
    string mysql="insert into admin_manage (adminuser,adminpass) values('"+uname+"','"+pass+"')";
    SqlCommand exec=new SqlCommand(mysql,Module.Connection.GetConnObj());
    exec.ExecuteNonQuery();
    Response.Write("新用户添加成功。");
    }
    }
    private bool checkUser(string uname)
    {
    bool a;
    string mysql="select * from admin_manage where adminuser='"+uname.ToLower() + "'";
    SqlCommand exec=new SqlCommand(mysql,Module.Connection.GetConnObj());
    SqlDataReader reader=exec.ExecuteReader();
    if (!reader.HasRows)
    {
    Response.Write("ok。可以注册");
    a=true;
    }
    else
    {
    Response.Write("Sorry.不允许注册该用户名,");
    a=false;
    }
    return a;
    }
    }
    }
    //==================================================================================aspx//=================================================================================
    <%@ Page language="c#" Codebehind="admin_addManage.aspx.cs" AutoEventWireup="false" Inherits="Demo_Database.Manage.admin_addManage" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>admin_addManage</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
    <asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 72px" runat="server"
    Width="56px" Height="16px">用户名</asp:Label>
    <asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 64px; POSITION: absolute; TOP: 136px" runat="server">密码</asp:Label>
    <asp:TextBox id="pass" style="Z-INDEX: 103; LEFT: 176px; POSITION: absolute; TOP: 104px" runat="server"
    TextMode="Password"></asp:TextBox>
    <asp:Label id="Label3" style="Z-INDEX: 104; LEFT: 64px; POSITION: absolute; TOP: 104px" runat="server">密码确认</asp:Label>
    <asp:TextBox id="pass2" style="Z-INDEX: 105; LEFT: 176px; POSITION: absolute; TOP: 136px" runat="server"
    TextMode="Password"></asp:TextBox>
    <asp:RequiredFieldValidator id="RequiredFieldValidator1" style="Z-INDEX: 106; LEFT: 360px; POSITION: absolute; TOP: 80px"
    runat="server" ErrorMessage="用户名不能为空" ControlToValidate="username" Width="112px"></asp:RequiredFieldValidator>
    <asp:CompareValidator id="CompareValidator1" style="Z-INDEX: 107; LEFT: 360px; POSITION: absolute; TOP: 144px"
    runat="server" ErrorMessage="2次密码不同" ControlToValidate="pass2" ControlToCompare="pass"></asp:CompareValidator>
    <asp:RequiredFieldValidator id="RequiredFieldValidator2" style="Z-INDEX: 108; LEFT: 360px; POSITION: absolute; TOP: 112px"
    runat="server" ErrorMessage="请填写密码" ControlToValidate="pass"></asp:RequiredFieldValidator>
    <asp:Button id="cmdReg" style="Z-INDEX: 109; LEFT: 160px; POSITION: absolute; TOP: 176px" runat="server"
    Text="注册"></asp:Button>
    <asp:Button id="cmdCancel" style="Z-INDEX: 110; LEFT: 216px; POSITION: absolute; TOP: 176px"
    runat="server" Text="取消"></asp:Button>
    <asp:TextBox id="username" runat="server" style="Z-INDEX: 111; LEFT: 176px; POSITION: absolute; TOP: 72px"></asp:TextBox>
    <asp:RegularExpressionValidator id="RegularExpressionValidator1" style="Z-INDEX: 112; LEFT: 480px; POSITION: absolute; TOP: 80px"
    runat="server" Width="96px" ControlToValidate="username" ErrorMessage="包含非法字符" ValidationExpression="\w+$"></asp:RegularExpressionValidator>
    </FONT>
    </form>
    </body>
    </HTML>
    //==================================================================================
      

  2.   

    //*****注册基本思路//****首创建一个用户表//****基本流程如下:用户点击注册进行注册页面---->提交相关协议--->填写人个人资料--->验证个人资料--->注册成功
    //*****验证用户是否重新ProcCreate Proc Proc_SystemUser_ExisitUser
    (
       @UserCode varchar(30),
       @ExitsState smallint output --验证状态,如果返回值为1的得话则表示该用户己注册过
    )
    as
    BEGIN
        DECLARE @USEREXITS INT;
        SELECT *  FROM  TB_SYSTEM_USER WHERE USERCODE=@USERCODE
        IF(@@ROWCOUNT<=0)
        BEGIN
          SET @USEREXITS =1;
          SET @ExitsState =@USEREXITS  
        END
        ELSE
        BEGIN
          SET    @USEREXITS=0;
         SET @USEREXITS =@USEREXITS
        END
    END