SHARE
TWEET

Untitled

Ortund Apr 22nd, 2014 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ###################
  2. // #  Login.aspx.cs  #
  3. // ###################
  4. protected void btnLogin_Click(object sender, EventArgs e)
  5. {
  6.     User us = new User(txtEmail.Text, txtPass.Text);
  7.     if (us.Login() != null)
  8.     {
  9.         generateSessionVars(us);
  10.         Response.Redirect("~/Members/Default.aspx");
  11.     }
  12.     else
  13.     {
  14.         lblErr.Text = "Invalid username or password.";
  15.     }
  16. }
  17.  
  18. // ######################
  19. // #  App_Code/User.cs  #
  20. // ######################
  21. public class User
  22. {
  23.     public int userid { get; protected set; }
  24.     public string email { get; protected set; }
  25.     public string pass { get; protected set; }
  26.  
  27.     myDatabaseContext db = new myDatabaseContext(); // contains object user as returned by Login()
  28.  
  29.     public User(string EmailAddress, string Password)
  30.     {
  31.         email = EmailAddress;
  32.         pass = Password;
  33.     }
  34.  
  35.     public user Login()
  36.     {
  37.         string salt = getSalt();
  38.         byte[] hash = HashPassword(pass, salt, SHA512);
  39.  
  40.         return user = (from u in db.users
  41.                         where u.email == email and u.pass == hash
  42.                         select u).FirstOrDefault();
  43.     }
  44.  
  45.     private string getSalt()
  46.     {
  47.         var salt = (from u in db.users
  48.                      where u.email == email
  49.                      select u.salt).FirstOrDefault();
  50.  
  51.         if (salt != null)
  52.         {
  53.             return salt.salt;
  54.         }
  55.         else
  56.         {
  57.             return String.Empty;
  58.         }
  59.     }
  60.  
  61.     public byte[] HashPassword(string ClearPassword, string Salt, SHA512 algorithm)
  62.     {
  63.         byte[] data = new byte[];
  64.         byte[] result;
  65.         SHA512 shaM = new SHA512Managed();
  66.         result = shaM.ComputeHash(data);
  67.     }
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top