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.

RegisterViewModel.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using Teknik.Areas.Profile.Models;
  4. using Teknik.Helpers;
  5. using Teknik.Models;
  6. namespace Teknik.Areas.Profile.ViewModels
  7. {
  8. public class RegisterViewModel
  9. {
  10. private TeknikEntities db = new TeknikEntities();
  11. [Required]
  12. [Display(Name = "Username")]
  13. public string Username { get; set; }
  14. [Required]
  15. [Display(Name = "Password")]
  16. [DataType(DataType.Password)]
  17. public string Password { get; set; }
  18. [Required]
  19. [Display(Name = "Confirm Password")]
  20. [DataType(DataType.Password)]
  21. public string ConfirmPassword { get; set; }
  22. public bool Insert()
  23. {
  24. bool success = true;
  25. try
  26. {
  27. User newUser = db.Users.Create();
  28. newUser.JoinDate = DateTime.Now;
  29. newUser.Username = Username;
  30. newUser.HashedPassword = SHA384.Hash(Username, Password);
  31. db.Users.Add(newUser);
  32. db.SaveChanges();
  33. }
  34. catch (Exception ex)
  35. {
  36. success = false;
  37. }
  38. return success;
  39. }
  40. }
  41. }