论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > asp教程
Tag:入门,文摘,实例,技巧,iis,表单,对象,上传,数据库,记录集,session,cookies,存储过程,注入,分页,安全,优化,xmlhttp,fso,jmail,application,防盗链,stream,组件,md5,乱码,缓存,加密,验证码,算法,ubb,正则表达式,水印,,日志,压缩,url重写,控件,函数,破解,触发器,socket,ADO,初学,聊天室,留言本,视频教程

用户注册及跟踪代码(一)

文章类别:asp | 发表日期:2008-10-5 20:41:26

用户注册册及确认在线的ASP程序。
1. SQL的表及储存过程
---------------------------------------------
CREATE TABLE [dbo].[userbaseinfo] (
    [userid] [varchar] (50) NOT NULL ,
    [password] [varchar] (50) NOT NULL ,
    [validcodelogin] [char] (50) NOT NULL ,
    [userlevel] [char] (1) NULL ,
    [logintime] [char] (50) NULL
) ON [PRIMARY]
GO

alter table userbaseinfo
add
constraint PK_userbaseinfo_userid
    primary key (userid)
Go

CREATE TABLE [dbo].[userdetailinfo] (
    [userid] [varchar] (50) NOT NULL ,
    [password] [varchar] (30) NOT NULL ,
    [realname] [varchar] (10) NULL ,
    [sex] [char] (10) NULL ,
    [birthday] [datetime] NULL ,
    [idcode] [varchar] (50) NULL ,
    [address] [varchar] (300) NULL ,
    [email] [varchar] (50) NULL ,
    [telephone] [varchar] (50) NULL
) ON [PRIMARY]
GO

alter table userdetailinfo
add
constraint PK_userdetailinfo_userid
    primary key (userid)
Go

SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON
GO

CREATE proc dbo.proc_GetRandom_internal
--取得校验码
    @minNum        integer,
    @maxNum        integer,
    @RandomNum    float output
as
set nocount on

declare @numRange integer
declare @ranSeed integer
declare @curTime  datetime

begin

  select @numRange=@maxNum-@minNum+1

  select @curTime=getdate()
  select @ranSeed=datediff(s,'2000-1-1',@curTime)  
  select @ranSeed=@ranSeed+1
  select @RandomNum=rand()*@numRange+@minNum
  --print @RandomNum
  return
end




GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


CREATE proc dbo.proc_GetValidCode_Internal
--取得校验码
    @CodeLength    integer,
    @ValidCode    varchar(10) output
as
set nocount on

declare @chrRnd char(1)
declare @chrRndNo integer

begin

  select @ValidCode=""

  while (@CodeLength>0)
  begin
    exec proc_GetRandom_internal 1,52,@chrRndNo output
    if @chrRndNo>26
      begin
       select @chrRndNo=@chrRndNo+6
      end
    select @chrRnd=char(@chrRndNo+64)
    select @ValidCode=@ValidCode+@chrRnd
    select @CodeLength=@CodeLength-1
  end
  print @validCode
  return
end



GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


CREATE proc dbo.proc_UserInfoUpdate
--用户更新个人信息
    @ValidCodeLogin  varchar(10),
    @RealName    Varchar(10),
    @Sex        Varchar(10),
    @Birthday    datetime,
    @IDCode        Varchar(50),
    @Address    Varchar(300),
    @eMail        Varchar(50),
    @Telephone    Varchar(50)
as

set nocount on

declare @UserValidFlag int
declare @ValidCodeReg varchar(30)
declare @UserLevel varchar(1)
declare @UserID varchar(30)

begin
exec proc_isUserValidbyCode_internal @ValidCodeLogin,@UserValidFlag output
if @UserValidFlag<0
  begin
    --select @UserValidFlag as resultID    
      -- -1 用户尚未登录
      -- -2 用户超时
    return @UserValidFlag
  end
  
select @UserID=UserID from UserBaseinfo where ValidCodeLogin=@ValidCodeLogin

Update UserDetailInfo
    set RealName=@RealName,
    Sex=@Sex,
    Birthday=@Birthday,
    IDCode=@IDCode,
    Address=@Address,
    eMail=@eMail,
    Telephone=@Telephone
  where
    UserID=@UserID;
         
if (@RealName="" or @Birthday="" or @Sex="" or @IDCode="" or @Address="" or @eMail="" or @Telephone="")
   begin
     --select -3 as resultID      
     return -3  --信息尚未全部填写
   end   

select 0 as resultID

end


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

create proc dbo.proc_UserLogOut
--用户退出
    @ValidCodeLogin  varchar(10)
as

set nocount on

declare @UserValidFlag int
declare @UserLevel varchar(9)

begin
exec proc_isUserValidbyCode_internal @ValidCodeLogin,@UserValidFlag output
if (@UserValidFlag<0)
  begin
    --select @UserValidFlag as resultID
    return @UserValidFlag
      -- -1 用户尚未登录
      -- -2 用户超时
  end

Update UserBaseInfo
    set ValidCodeLogin='',
        LoginTime='1970-1-1'
  where
    ValidCodeLogin=@ValidCodeLogin
         
--select 0 as resultID
return 0
end    

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


CREATE proc dbo.proc_UserRegBase
--用户基本资料注册
    @UserID        Varchar(30),
    @Password    Varchar(30)
as

set nocount on

declare @UserLevel varchar(9)
--declare @ValidCodeReg varchar(10)
declare @ValidCodeLogin  varchar(10)
declare @LoginTime  datetime
declare @userExist int
declare @PwdLength int

begin
select @UserLevel="0"
select @PwdLength=4
if (datalength(@Password)<@PwdLength)
   begin
     select -4 as returnID
     return -4        --密码长度不够
   end

--exec proc_GetValidCode_internal 10,@ValidCodeReg output    --取得用户注册校验码
exec proc_GetValidCode_internal 10,@ValidCodeLogin output    --取得用户登录校验码
exec proc_isUserExist_internal @UserID,@userExist output    --取得用户存在标志
select @LoginTime=getdate()
print @userExist
if @userExist=0
  begin
    select -1 as resultID
    return -1  --用户已存在
  end

--插入用户基本信息表
insert into UserBaseInfo
   (UserID,Password,UserLevel,ValidCodeLogin,LoginTime)
   Values(@UserID,@Password,@UserLevel,@ValidCodeLogin,@LoginTime)

--插入用户详细信息表
insert into UserDetailInfo
   (UserID,Password) Values(@UserID,@Password)


--取得用户注册校验码,登录校验码
select 0 as resultID
select ValidCodeLogin from UserBaseInfo where UserID=@UserID

return 0
end


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


create proc dbo.proc_isUserExist_internal
--判断用户名是否存在
    @UserID        Varchar(30),
    @existFlag    int output
as

set nocount on
begin

if not EXISTS(select * from UserBaseInfo where UserID=@UserID)
   begin
    select @existFlag =-1
    return
   end
select @existFlag =0   
return
end

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


create proc dbo.proc_isUserValidbyCode_internal
--用户身份检验(根据登录校验码)
    @ValidCodeLogin  varchar(10),
    @validFlag    int output
as

set nocount on

declare @LoginTime  datetime
declare @curTime  datetime
declare @diffTime  datetime

begin
if not EXISTS(select * from UserBaseInfo where ValidCodeLogin=@ValidCodeLogin)
  begin
    select @validFlag=-1   --用户尚未登录
    return
  end

select @LoginTime = (select LoginTime from UserBaseInfo where ValidCodeLogin=@ValidCodeLogin)
select @curTime=getdate()
select @diffTime=datediff(hh,@LoginTime,@curTime)
if @diffTime>=10
  begin
    select @validFlag=-2    --用户超时
    return  
  end

select @LoginTime=getdate()                --取得用户最后登录时间
update UserBaseInfo set LoginTime=@LoginTime where ValidCodeLogin=@ValidCodeLogin

select @validFlag=0
return
end

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


上一篇:{实例}用户注册及跟踪代码(二) 人气:4907
下一篇:{实例}简单ASP论坛DIY 人气:4561
视频教程列表
文章教程搜索
 
Asp推荐教程
Asp热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058