ndomizer = new Random (); saltBuilder = new StringBuilder (randomizer.Next (4, 14)); (int i = 0; i
{. Next ();. Append (((char) randomizer.Next (0x21, 0x7e)));
} salt = saltBuilder.ToString ();
authData = Encoding.UTF8.GetBytes (salt + passwd + login); hasher = new SHA512Managed (); hash = Convert.ToBase64String (hasher.ComputeHash (authData)); user = new User ()
{= Guid.NewGuid (), = salt, = login, = hash, = name
};. Users.AddObject (user);. SaveChanges (); (user.id, Guid.NewGuid ()); (var ctx =
{. Write (logo);
} Json (new UserModel (user));
}
ActionResult Login ()
{View ();
}
[HttpPost] ActionResult Login (string login, string passwd)
{user = Dc.Users.SingleOrDefault (x => x.login == login); (user! = null)
{authData = Encoding.UTF8.GetBytes (user.salt + passwd + login); hasher = new SHA512Managed (); hash = Convert.ToBase64String (hasher.ComputeHash (authData));
(hash == user.password)
{js = Json (new UserModel (user)); ses = new Session () {uid = user.id, id = Guid.NewGuid ()}; (user.id, ses.id ); js;
}
} Content ("fail");
}
[Authorized] ActionResult Logout ()
{sesid = Guid.Parse (System.Web.HttpContext.Current.Request.Cookies ["sesid"]. Value); uid = Guid.Parse (System.Web.HttpContext.Current. Request.Cookies ["uid"]. Value); ses = Dc.Sessions.SingleOrDefault (x => x.id == sesid && x.uid == uid); (ses! = null)
{(Guid.Empty, Guid.Empty); RedirectToAction ("Login");
} Content ("fail");
} int SetSession (Guid uid, Guid sesid)
{dc = new WINEntities (); (sesid == Guid.Empty)
{= Guid.Parse (System.Web.HttpContext.Current.Request.Cookies ["sesid"]. Value); s = dc.Sessions.Single (x => x.id == sesid);. Sessions.DeleteObject (s);. SaveChanges ();. Response.Clear (); 0;
}
}
}
wIN_test_1_.Controllers
{class HomeController: Controller
{
[Authorized] ActionResult Index ()
{View ();
} ActionResult About ()
{View ();
}
[HttpPost]