我得database里面有两个密码,都是nvarchar类型,一个是password,另外一个passwordsalt.比如(
ku9R715tO4D68kZPPB+umqiLSaM=,NeTBuehQYFbJLe3BBZvLwg==),我用membership去看,显示是用SHA1来加密得。那我现在验证登陆用户得话。怎么实现啊?急s我了,请大家帮帮忙。万分感谢

解决方案 »

  1.   

    passwordFormat="Hashed" 我查了下,machine.config里面是这样申明得
      

  2.   

    那把输入好的密码,通过加密算法转换成加密后的字符串,然后进行查询,例如:sql:
    select * from yourTable where yourUserName=@UserName and yourPwd = @Pwd//c# program
    string strPwd = EncrytoData( yourInputValue );//Use "strPwd" to query database
      

  3.   

    先从数据库中取出passwordsalt然后再将要验证的密码使用原来的算法加密,将加密后的结果与数据库中的密码比较
      

  4.   

    TO avisnet(第十维度) 
    我刚才也用了这个方法测试了一遍,生成得密码有40位,而数据库里普遍都只有28位
      

  5.   

    你再看看你用的加密码方法吧public static string EncodePassword(string hashAlgorithmType, string password, string salt)
    {
    byte[] passwordBuf = System.Text.Encoding.Unicode.GetBytes(password);
    byte[] saltBuf = Convert.FromBase64String(salt); byte[] buf = new byte[passwordBuf.Length + saltBuf.Length]; Buffer.BlockCopy(saltBuf, 0, buf, 0, saltBuf.Length);
    Buffer.BlockCopy(passwordBuf, 0, buf, saltBuf.Length, passwordBuf.Length); HashAlgorithm hashAlgorithm = HashAlgorithm.Create(hashAlgorithmType);
    buf = hashAlgorithm.ComputeHash(buf);
    return Convert.ToBase64String(buf);
    }
    只要上面函数的三个参数是相同的,那么返回的加密码肯定是一致的
      

  6.   

    if(Membership.ValidateUser(userName,passWord)
    {
       //用户登陆的操作
    }else
    {
    }
      

  7.   

    TO avisnet(第十维度) 
    你函数里传进来得salt是指什么
      

  8.   

    salt是数据库中的passwordsalt在数据库中添加一个用户时,passwordsalt应该是随机产生的,之后被保存在数据中,验证时再从数据库中取出passwordsalt。public static string GenerateSalt(int saltLength)
    {
    byte[] salt = new byte[saltLength];
    (new System.Security.Cryptography.RNGCryptoServiceProvider()).GetBytes(salt);
    return Convert.ToBase64String(salt);
    }