【发布时间】:2022-01-17 13:20:47
【问题描述】:
我是 PLSQL 的新手,不知道如何从 Oracle 存储过程中获取价值。我该如何解决这个问题?
System.Exception:'参数'结果':没有为可变长度数据类型设置大小:字符串。'
我正在使用 Iracle 10g
程序:
PROCEDURE LoginAuthentication(uid in users.userid%type,pass in users.password%type,result out users.role%type)
is
rl users.role%type;
c number;
begin
select role into rl from users where userid=uid and password=pass and status=1;
select count(*) into c from users where userid=uid and password=pass and status=1;
if(c=1) then
result:=rl;
else
result:='null';
end if;
exception
when no_data_found then
result:='null';
end LoginAuthentication;
代码:
public string Login(String id, string password)
{
using (OracleConnection oCon = new OracleConnection("DATA SOURCE = localhost:1521;USER ID = PROJECTDB;Password=pass"))
{
OracleCommand Cmd = new OracleCommand();
try
{
Cmd.Connection = oCon;
Cmd.CommandText = " user_package.LoginAuthentication";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.Add("uid", OracleType.VarChar).Value = id;
Cmd.Parameters.Add("pass", OracleType.VarChar).Value = password;
Cmd.Parameters.Add("result", OracleType.VarChar).Direction = ParameterDirection.Output;
oCon.Open();
Cmd.ExecuteNonQuery();
string result = Cmd.Parameters["result"].Value.ToString();
return result;
}
catch (Exception ex)
{
throw ex;
}
finally
{
oCon.Close();
}
}
}
错误:
System.Exception:'参数'结果':没有为可变长度数据类型设置大小:字符串。
【问题讨论】:
-
错误说明了问题所在(您需要指定参数大小,而不仅仅是值),但更大的问题是不安全的密码代码。密码永远不应该以明文形式存储,它们应该被加盐和散列多次(至少 1000 次)。而
null这个词与空值不同。想象一下,如果有人创建了一个名为null的角色会发生什么。 -
自 2002 年以来的所有 .NET 堆栈都具有安全身份验证和密码存储功能。如果可以的话,不要自己动手。如果您绝对必须(为什么?)使用Rfc2898DeriveBytes 类使用加密强算法对密码进行哈希处理。就像`k1 = new Rfc2898DeriveBytes(pwd1, salt1, myIterations);`然后调用
var hash=k1.GetBytes(20);
标签: c# .net oracle stored-procedures plsql