public static string GeneratePassword(ApplicationUser userToSave, string password)
        {
            string initVector = password;

            int remainingDigits = 16 - password.Length;

            if (remainingDigits > 0)
            {
                for (int i = 1; i <= remainingDigits; i++)
                {
                    initVector += "*";
                }
            }

            return RJindael.Encrypt(userToSave.SecurityHash, userToSave.UserID.ToString(), userToSave.PhoneNumber, "SHA1", 37, initVector, 256);
        }
        public IHttpActionResult CreateUser(ApplicationUserViewModel user)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser userToSave = new ApplicationUser
                {
                    Name = user.Name,
                    Password = "******",
                    SecurityHash = string.Empty,
                    PhoneNumber = user.PhoneNumber,
                    JoinTS = DateTime.Now,
                    Active = true
                };

                using (DbContextTransaction transaction = context.Database.BeginTransaction())
                {
                    context.ApplicationUsers.Add(userToSave);

                    context.SaveChanges();

                    userToSave.SecurityHash = UserManager.GenerateSecurityHash(userToSave, user.Password);

                    userToSave.Password = UserManager.GeneratePassword(userToSave, user.Password);

                    context.Entry<ApplicationUser>(userToSave).State = EntityState.Modified;

                    context.SaveChanges();

                    transaction.Commit();
                }

                return Ok(new ResponseModel
                {
                    Success = true,
                    Message = "User Created Successfully.",
                    Data = new { userId = userToSave.UserID, url = ConfigurationManager.AppSettings["app:ApiUrl"] + "account/" + userToSave.UserID }
                });
            }
            else
            {
                return BadRequest(ModelState);
            }
        }
 public static string GenerateAccessToken(ApplicationUser userToLogin)
 {
     return RJindael.Encrypt(Json.Encode(userToLogin), userToLogin.Password, userToLogin.SecurityHash, "SHA1", 47, "****************", 256);
 }