我是CS专业,我刚刚完成了ASP.net网站的设计,对于网站我需要一个登录认证系统......我不想使用SQLMembershipProvider,因为我真的想学习如何自己创建一个......无论如何,这就是我想出来的,我想知道是否有人可以给我一些反馈,提示或建议.
提前致谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Security.Cryptography;
/// <summary>
/// Summary description for PwEncrypt
/// </summary>
public class PwEncrypt
{
public const int DefaultSaltSize = 5;
private static string CreateSalt()
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buffer = new byte[DefaultSaltSize];
rng.GetBytes(buffer);
return Convert.ToBase64String(buffer);
}
public static string CreateHash(string password, out string salt)
{
salt = CreateSalt();
string saltAndPassword = String.Concat(password, salt);
string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(saltAndPassword, "SHA1");
hashedPassword = string.Concat(hashedPassword, salt);
return hashedPassword; …Run Code Online (Sandbox Code Playgroud) 如何使用三元运算符缩短以下内容?
if ((pos - maxPos) == (c.clientWidth)) {
$j("#next").addClass("filter");
} else {
$j("#next").removeClass("filter");
}
Run Code Online (Sandbox Code Playgroud)