主要是判断用户名和密码,输入参数为用户名和密码,如果用户名不存在,那么返回nouser,如果用户名存在密码不对就返回pwd,如何全正确就返回ok
下面这个是用java代码实现的,我想用sql过程实现
public String isValidateLogin(String userName, String userPass) {
String result = null;
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
con = DBConnection.getConnection();
try {
stmt = con
.prepareStatement("select userPass from login where userName=?");
stmt.setString(1, userName);
rs = stmt.executeQuery();
if (rs.next()) {
if (userPass.equals(rs.getString(1))) {
result = "OK";
} else {
result = "PWDERROR";
} } else {
result = "NOUSER";
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (con != null) {
con.close();
con = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return result;
}

解决方案 »

  1.   

    输入的参数要进行左右去空格.相关于trim()
      

  2.   

    if exists (select * from sysobjects where name='proc_pass')
    drop proc proc_pass
    GOcreate procedure proc_pass
    @username varchar(10),
    @password varchar(10),
    @result varchar(10) output
    Asset nocount on
    declare @pass varchar(10)if exists(select Upassword from userinfo where Uname=@username)
        begin
    select @pass=Upassword from userinfo where Uname=@username
    if (@password=@pass)
              set @result='ok'
    else
             set @result='pwderror'
        end
    else
        set @result='nouser'print @result