c# - “索引超出数组边界”错误背后的原因
问题描述
我编写了一个从数据库中检索散列密码并将其与登录表单中的密码进行比较的代码。
if (usercheck.HasRows)
{
while (usercheck.Read())
{
string hashst = usercheck.GetValue(1).ToString();
byte[] hashBytes = Convert.FromBase64String(hashst);
byte[] salt = new byte[16];
Array.Copy(hashBytes, 0, salt, 0, 16);
var pbkdf2 = new Rfc2898DeriveBytes(passsign.Text, salt, 100000);
byte[] hash = pbkdf2.GetBytes(20);
for (int i = 0; i < 20; i++)
if (hashBytes[i + 16] != hash[i])
{
lblUsPsav.Text = "Incorrect Password";
}
else
{
Response.Redirect(String.Format("./Profile.aspx"));
}
但是,错误显示代码上的“索引超出了错误的范围”
for (int i = 0; i < 20; i++)
我不知道为什么。相反,关于数据检索和其他任何事情,代码都可以完美运行。
解决方案
推荐阅读
- c# - 未从 asmx 页面 asp.net 接收到 ajax 函数的查询结果
- python - 错误:函数 'detectMultiScale' 中的 !empty()
- ios - SwiftUI .onAppear,只运行一次
- python - 如何使用 sympy 根据布尔方程组中的其他变量提取布尔变量的值?
- unity3d - 片段着色器 fmod,为什么不重复
- amazon-web-services - 为什么我会收到关于 nginx Web 服务器关闭或忙碌的错误?
- html - 无法在 React ERR_INVALID_URL 中显示从 mongodb 检索到的 base64 图像
- node.js - 当我执行“npm start”时,我在安装 reactjs 时遇到问题
- javascript - 使用Javascript将像素转换为视口单位的问题
- python - 使用提供的密钥加密文本 python