The next generation of the Teknik Services. Written in ASP.NET.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoginViewModel.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Security;
  7. using Teknik.Helpers;
  8. using Teknik.Models;
  9. namespace Teknik.Areas.Profile.ViewModels
  10. {
  11. public class LoginViewModel
  12. {
  13. private TeknikEntities db = new TeknikEntities();
  14. [Required]
  15. [Display(Name = "Username")]
  16. public string Username { get; set; }
  17. [Required]
  18. [Display(Name = "Password")]
  19. [DataType(DataType.Password)]
  20. public string Password { get; set; }
  21. [Display(Name = "Remember Me")]
  22. public bool RememberMe { get; set; }
  23. public bool IsValid()
  24. {
  25. return IsValid(Username, Password);
  26. }
  27. public bool IsValid(string username, string password)
  28. {
  29. var myUser = db.Users.Where(b => b.Username == username).FirstOrDefault();
  30. if (myUser != null && !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
  31. {
  32. return (myUser.HashedPassword == SHA384.Hash(username, password));
  33. }
  34. return false;
  35. }
  36. }
  37. }