在一个登录框中,要求验证多种角色的用户登录信息,并且转到各自的信息页面。
有什么简单的方法实现这功能。

解决方案 »

  1.   

    create proc userlogin(@usermame varchar(20),@userpassward varchar(20),@userroleid int,@returninfo varchar(50) output)
    as
    begin
      if not exists(select 1 from tb_userinfo where username=@username and userroleid=@userroleid)
     begin 
      set @returninfo='用户名不存在'
     end
     else if not exists(select 1 from tb_userinfo where username=@username and userroleid=@userroleid and userpassward=@userpassward)
    begin
    set @returninfo="密码错"
    end
    else 
    begin
    insert into tb_userloginInfo .....
    set @returninfo="成功"
    end
    end
      

  2.   

    我刚开始想的哈,是在实现过程中全部用代码实现多个角色在统一登录框中的验证过能,只是写几个if else语句来一个个表来查询验证的过程罢了,然后在请求转发页面。
    其实和存储过程使用的道理是一样的,只是存储过程这个过程由数据库完成,后面有人为编码完成。两个其实是一样。
      

  3.   

    我给大家看下我创建的存储过程来验证以登录框中的多个角色的功能。
    希望各位大侠们们看看还有什么问题。create proc loginCheck(@userName varchar(16),@userPassword varchar(6),@No int output)
    as
     begin
      if exists (select 1 from personalUserInfo where userName = @userName and userPassword = @userPassword)
        begin 
         set @No = 1
         end
     else if exists (select 1 from enterpriseUserInfo where enterpUserName =@userName and enterpUserPassword = @userPassword )
          begin
         set   @No=1
         end
     else
        begin
      set @No=0
        end
    end
      

  4.   

    系统肯定要求安全性能要过得去,至少要能够防范SQL注入的入侵。那么用2楼的就是明智之举了。三楼的简单易行。
      

  5.   


    create proc loginCheck(@userName varchar(16),@userPassword varchar(6),@No int output)
    as
     begin
      if exists (select 1 from personalUserInfo where userName = @userName and userPassword = @userPassword)
        begin 
         set @No = 1
         end
     else if exists (select 1 from enterpriseUserInfo where enterpUserName =@userName and enterpUserPassword = @userPassword )
          begin
         set   @No=2
         end
     else
        begin
      set @No=0
        end
    end
    像上面的哈,我想可以用存储过程实现多个表的一次验证功能(但是这需要保证多个表数据的唯一性),同时要求使用设置不同值(@NO)来不同表的查询过程。在写代码的时候通过判断查询判断的值就行了,这样在前面代码就会简洁很多,全部由数据库的存储过程去验证数据的有效性。