public void Provided_Password_Does_Not_Match_User_Password()
        {
            string providedPassword = "******";

            string hashedProvidedPassword = PasswordEncoder.Encode(providedPassword);
            string hashedUserPassword     = PasswordEncoder.Encode(_user.Password);

            bool result = PasswordComparer.ComparePasswords(hashedProvidedPassword, hashedUserPassword);

            Assert.IsFalse(result);
        }
        public void Provided_Password_Matches_User_Password()
        {
            string providedPassword = "******";

            string hashedProvidedPassword = PasswordEncoder.Encode(providedPassword);
            string hashedUserPassword     = PasswordEncoder.Encode(_user.Password);

            bool result = PasswordComparer.ComparePasswords(hashedProvidedPassword, hashedUserPassword);

            Assert.IsTrue(result);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            PasswordEncoder encoder = new PasswordEncoder();

            var user = "******";
            var pwd  = "#brasil@01";
            var salt = encoder.DefaultSalt[36];

            var result = encoder.Encode(salt + user + pwd);

            Console.WriteLine(result);
            Console.ReadKey();
        }
Exemple #4
0
        public JsonResult register(User user)
        {
            RegisterModelAndView result = new RegisterModelAndView();

            if (user.Email.Equals(""))
            {
                result.Errors.Add("email is null");
            }
            if (user.Fullname.Equals(""))
            {
                result.Errors.Add("fullname is null");
            }
            if (user.Username.Equals(""))
            {
                result.Errors.Add("username is null");
            }
            if (user.Password.Equals(""))
            {
                result.Errors.Add("password is null");
            }
            if (userDatabase.RegisterVerificationEmail(user.Email))
            {
                result.Errors.Add("this email is already used");
            }
            if (userDatabase.RegisterVerificationUsername(user.Username))
            {
                result.Errors.Add("this username is already used");
            }

            if (result.Errors.Count == 0)
            {
                try
                {
                    user.Password = passwordEncoder.Encode(user.Password);
                    userDatabase.Register(user);

                    result.Message = "Register is a success";
                    result.Success = true;
                }
                catch
                {
                    result.Message = "Problem with dataBase";
                }
            }
            else
            {
                result.Message = "Register is not a success";
            }
            return(new JsonResult(result));
        }
Exemple #5
0
 /// <summary>
 /// 用户管理:新增
 /// </summary>
 /// <param name="sys_user"></param>
 public MsgModel AddUser(sys_user sys_user)
 {
     sys_user.password    = PasswordEncoder.Encode(_sysConfigService.GetConfigItem("user.init.password"));
     sys_user.create_time = DateTime.Now; //创建时间
     sys_user.enabled     = true;         //新增用户激活
     if (_baseSysUserService.GetModels(a => a.username == sys_user.username).Any())
     {
         return(MsgModel.Fail(StatusCodes.Status500InternalServerError, "用户名已存在,不能重复"));
     }
     if (!_baseSysUserService.Insert(sys_user))
     {
         return(MsgModel.Fail("新增用户失败!"));
     }
     return(MsgModel.Success("新增用户成功!"));
 }
Exemple #6
0
        /// <summary>
        /// 用户管理:重置密码
        /// </summary>
        /// <param name="userId"></param>
        public MsgModel PwdReset(long userId)
        {
            sys_user sys_user = _baseSysUserService.GetModels(a => a.id == userId).ToList().SingleOrDefault();

            sys_user.id       = userId;
            sys_user.password = PasswordEncoder.Encode(_sysConfigService.GetConfigItem("user.init.password"));
            var  length = sys_user.password.Length;
            bool result = _baseSysUserService.UpdateRange(sys_user);

            if (!result)
            {
                return(MsgModel.Fail(StatusCodes.Status500InternalServerError, "密码重置失败!"));
            }
            return(MsgModel.Success("密码重置成功!"));
        }
Exemple #7
0
        /// <summary>
        /// 个人中心:修改密码
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="oldPass"></param>
        /// <param name="newPass"></param>
        public MsgModel ChangePwd(string userName, string oldPass, string newPass)
        {
            sys_user sys_user = _baseSysUserService.GetModels(a => a.username == userName).SingleOrDefault();
            // 判断旧密码是否正确
            bool isMatch = PasswordEncoder.IsMatch(sys_user.password, oldPass);

            if (!isMatch)
            {
                return(MsgModel.Fail("原密码输入错误,请确认后重新输入!"));
            }
            sys_user.password = PasswordEncoder.Encode(newPass);
            var result = _baseSysUserService.UpdateRange(sys_user);

            return(result ? MsgModel.Success("密码修改成功!") : MsgModel.Fail("密码修改失败!"));
        }
        public IHttpActionResult GetHash(string email, string password)
        {
            try
            {
                var hash = new PasswordEncoder();
                var salt = hash.DefaultSalt[2];

                var crypt = hash.Encode(salt + email + password);

                return(Ok(crypt));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Exemple #9
0
        public void Encode_abc_bcd_key1()
        {
            // A A A
            // arrange
            var str      = "abc";
            var expected = "bcd";
            var key      = 1;

            //act
            var actual = PasswordEncoder.Encode(str, key);

            // assert
            Assert.AreEqual(expected, actual);
            //StringAssert.Contains();
            //CollectionAssert.AreEqual();
        }
 public IHttpActionResult LoginUser([FromBody] LoginUserBindingModel loginUserModel)
 {
     try
     {
         var user = UnitOfWork.UserRepository.GetByName(loginUserModel.UserName);
         if (user != null &&
             user.PasswordHash == PasswordEncoder.Encode(loginUserModel.Password))
         {
             return(Ok(Mapper.Map <User, UserReturnModelWithToken>(user)));
         }
         return(BadRequest());
     }
     catch (Exception)
     {
         return(InternalServerError());
     }
 }
        public async Task <ActionResult> CreateAccount(AppUser user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var pwd = new PasswordEncoder();

                    var hash = pwd.Encode(pwd.DefaultSalt[5] + user.Password, EncryptType.SHA_512);
                    user.Password = hash;

                    var role = db.UserRoles.FirstOrDefault(x => x.Id.ToString() == "822f4875-0aca-11e8-bbbb-7a79195ecca3");
                    user.UserRoleId = role.Id;

                    db.AppUsers.Add(user);
                    await db.SaveChangesAsync();

                    AppUser u = db.AppUsers.FirstOrDefault(o => o.Name.Equals(user.Name) &&
                                                           o.Password.Equals(hash));

                    if (u != null)
                    {
                        FormsAuthentication.SetAuthCookie(u.Email, true);
                        return(RedirectToAction("Index", "Products"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Erro");
                    }

                    return(RedirectToAction("Index", "Products"));
                }

                return(View(user));
            }
            catch (Exception ex)
            {
                ApplicationLog.Save(ex, ApplicationLog.ImpactLevel.High);
                return(View());
            }
        }
        private void OnCommandUserNew(string[] args)
        {
            string uid = args.Length > 0 ? args[0] : BConsole.ReadLine("uid: ");

            if (string.IsNullOrEmpty(uid))
            {
                return;
            }

            // existing uid?
            if (GameDB.Users.Contains(uid))
            {
                BConsole.WriteLine("uid: ", Color.DarkGreen, uid, " already exists!");
                return;
            }

            // password
            string password = BConsole.ReadPassword("password: "******"password confirm: ");

            if (password != confirm)
            {
                BConsole.WriteLine("password mismatch with password confirm!");
                return;
            }

            // insert user with encrypted password
            string passcode = PasswordEncoder.Encode(password);
            bool   result   = GameDB.Users.Insert(new User(uid, passcode));

            BConsole.WriteLine("creating new user(", uid, ")=", result);
        }
Exemple #13
0
        /// <summary>
        /// 微信授权登录
        /// </summary>
        /// <param name="wxAuth"></param>
        /// <returns></returns>
        public MsgModel AuthLogin(WXAuth wxAuth)
        {
            var wxDecrypt   = WxDecrypt(wxAuth.EncryptData, wxAuth.SessionId, wxAuth.IV);
            var dict        = JsonConvert.DeserializeObject <Dictionary <string, object> >(wxDecrypt);
            var phoneNumber = dict["phoneNumber"].ToString();
            var user        = _baseService.GetModels(a => a.phone == phoneNumber).SingleOrDefault();

            if (user != null) // 登录
            {
                return(_jwtAuthService.Login(user.username, user.password));
            }
            else // 注册
            {
                // 加密登录密码
                var initPassword = PasswordEncoder.Encode(CommonUtils.GetStringRandom(10));
                var userDto      = new SysUser
                {
                    phone    = phoneNumber,
                    password = initPassword
                };
                return(_jwtAuthService.SignUp(userDto));
            }
        }
        private void OnCommandLogin(string[] args)
        {
            // uid
            string uid = BConsole.ReadLine("uid: ");

            if (string.IsNullOrEmpty(uid))
            {
                return;
            }

            // password
            string password = BConsole.ReadPassword("password: ");

            if (string.IsNullOrEmpty(password))
            {
                return;
            }

            // encoded password
            string passcode = PasswordEncoder.Encode(password);

            // send login message
            GameClient.Login(uid, passcode);
        }
Exemple #15
0
        private static void ConfigureAutoMapper()
        {
            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <User, UserReturnModel>()
                .ForMember("Id", opt => opt.MapFrom(src => src.Id))
                .ForMember("UserName", opt => opt.MapFrom(src => src.UserName))
                .ForMember("Email", opt => opt.MapFrom(src => src.Email))
                .ForMember("FirstName", opt => opt.MapFrom(src => src.FirstName))
                .ForMember("LastName", opt => opt.MapFrom(src => src.LastName))
                .ForMember("Sex", opt => opt.MapFrom(t =>
                                                     (t.Sex == SexEnum.Male ? "Male" :
                                                      (t.Sex == SexEnum.Female ? "Female" : "Unknown"))))
                .ForMember("BirthDate", opt => opt.MapFrom(t =>
                                                           t.BirthDate.Date.ToString("yyyy-MM-dd")))
                .ForMember("AvatarUrl", opt => opt.MapFrom(t => t.AvatarUrl ??
                                                           HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)
                                                           + @"/Avatars/default_avatar.png"));

                cfg.CreateMap <User, UserReturnModelWithToken>()
                .ForMember("Token", opt => opt.MapFrom(t =>
                                                       JwtManager.GenerateToken(t.UserName, t.PasswordHash, 12)))
                .ForMember("Id", opt => opt.MapFrom(src => src.Id))
                .ForMember("UserName", opt => opt.MapFrom(src => src.UserName))
                .ForMember("Email", opt => opt.MapFrom(src => src.Email))
                .ForMember("FirstName", opt => opt.MapFrom(src => src.FirstName))
                .ForMember("LastName", opt => opt.MapFrom(src => src.LastName))
                .ForMember("Sex", opt => opt.MapFrom(t =>
                                                     (t.Sex == SexEnum.Male ? "Male" :
                                                      (t.Sex == SexEnum.Female ? "Female" : "Unknown"))))
                .ForMember("BirthDate", opt => opt.MapFrom(t =>
                                                           t.BirthDate.Date.ToString("yyyy-MM-dd")))
                .ForMember("AvatarUrl", opt => opt.MapFrom(t => t.AvatarUrl ??
                                                           HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)
                                                           + @"/Avatars/default_avatar.png"));

                cfg.CreateMap <CreateUserBindingModel, User>()
                .ForMember("PasswordHash", opt => opt.MapFrom(t =>
                                                              PasswordEncoder.Encode(t.Password)))
                .ForMember("AvatarUrl", opt => opt.MapFrom(t =>
                                                           "https://robohash.org/" + t.UserName))
                .ForMember("Sex", opt => opt.MapFrom(t =>
                                                     (t.Sex == "Male" ? SexEnum.Male:
                                                      (t.Sex == "Female" ? SexEnum.Female : SexEnum.Unknown))));

                cfg.CreateMap <Message, MessageReturnModel>()
                .ForMember("Id", opt => opt.MapFrom(src => src.Id))
                .ForMember("Text", opt => opt.MapFrom(src => src.Text))
                .ForMember("FirstName", opt => opt.MapFrom(src => src.Sender.FirstName))
                .ForMember("DateTime", opt => opt.MapFrom(t => t.DateTime
                                                          .ToString("MM/dd/yyyy HH:mm:ss")));

                cfg.CreateMap <Message, ConversationReturnModel>()
                .ForMember("Text", opt => opt.MapFrom(src => src.Text))
                .ForMember("DateTime", opt => opt.MapFrom(t => t.DateTime
                                                          .ToString("MM/dd/yyyy HH:mm:ss")))
                .ForMember("OtherUserId", opt =>
                           opt.ResolveUsing((source, dest, arg3, arg4) =>
                                            ((User)arg4.Options.Items["User"]).Id))
                .ForMember("FirstName", opt =>
                           opt.ResolveUsing((source, dest, arg3, arg4) =>
                                            ((User)arg4.Options.Items["User"]).FirstName))
                .ForMember("LastName", opt =>
                           opt.ResolveUsing((source, dest, arg3, arg4) =>
                                            ((User)arg4.Options.Items["User"]).LastName))
                .ForMember("AvatarUrl", opt =>
                           opt.ResolveUsing((source, dest, arg3, arg4) =>
                                            ((User)arg4.Options.Items["User"]).AvatarUrl))
                .ForMember("NewMessagesCount", opt =>
                           opt.ResolveUsing((source, dest, arg3, arg4) =>
                                            arg4.Options.Items["NewMessagesCount"]))
                .ForMember("Online", opt =>
                           opt.ResolveUsing((source, dest, arg3, arg4) =>
                                            arg4.Options.Items["Online"]));
            });
        }
Exemple #16
0
        public async void Register()
        {
            RegAnimate = true;
            bool _Error = false;

            //Diagnostics
            string Message    = string.Empty;
            string StackTrace = string.Empty;

            //Register user credentials
            await Task.Run(() =>
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(Username))
                    {
                        throw new ArgumentNullException("Username cannot be empty. Please try again");
                    }
                    if (string.IsNullOrWhiteSpace(Password))
                    {
                        throw new ArgumentNullException("Password cannot be empty. Please try again");
                    }
                    if (string.IsNullOrWhiteSpace(ConfirmPassword))
                    {
                        throw new ArgumentNullException("Password cannot be empty. Please try again");
                    }
                    if (!Password.Equals(ConfirmPassword))
                    {
                        throw new ArgumentNullException("Passwords do not match");
                    }

                    //Regex validation = new Regex(_EmailValidator, RegexOptions.CultureInvariant);
                    //if (!validation.IsMatch(Username))
                    //    throw new InvalidDataException("Your username does not appear to be an email address. Please try again");

                    //First & Last Name
                    if (string.IsNullOrWhiteSpace(FirstName))
                    {
                        throw new ArgumentNullException("First name cannot be empty");
                    }
                    if (string.IsNullOrWhiteSpace(LastName))
                    {
                        throw new ArgumentNullException("Last name cannot be empty");
                    }

                    //Generate Account
                    Account obj              = new Account();
                    obj.Contact_ID_Ref       = Guid.NewGuid().ToString();
                    obj.FirstName            = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(FirstName);
                    obj.LastName             = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(LastName);
                    obj.SiteUser_DisplayName = $"{ obj.FirstName } { obj.LastName }";

                    obj.Sys_Creation    = DateTime.Now;
                    obj.Sys_Transaction = DateTime.Now;

                    //Has the passwords on account generation and on login
                    PasswordEncoder hasher = new PasswordEncoder();
                    obj.Username           = Username;
                    obj.Password           = Password;

                    obj.Mobile          = Mobile;
                    obj.Work            = Work;
                    obj.Email           = Username;
                    obj.Home            = Home;
                    obj.Avatar          = Avatar_File;
                    obj.Avatar_FilePath = Avatar;

                    if (accountManager != null)
                    {
                        var hashedPassword = hasher.Encode(Password, EncryptType.SHA_512);
                        if (!accountManager.AuthenticateSiteUser_ByCredentials(obj.Username, hashedPassword))
                        {
                            //Add Accounts via the server Via a background service. Update the Guid based on the Id
                            Task.Run(() =>
                            {
                                try
                                {
                                    DataVaultAccountServiceClient serviceClient = new DataVaultAccountServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.AccountsInSecureUrl));

                                    var response = serviceClient._Generate_AccountForUser(LocalMapper.MapAccount_ToServer(obj));
                                    if (response.Errors.Count != 0)
                                    {
                                        response.Errors.ForEach(w =>
                                        {
                                            var log = LocalMapper.Map_LogWithError(w, string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

                                            if (this.logging != null)
                                            {
                                                this.logging.AddLog(log);
                                            }
                                        });
                                    }
                                    else
                                    {
                                        accountManager.Update_AccountGuidByUsername(Username, response.Contact_ID);
                                        Constants.InMemory_ContactID = response.Contact_ID;
                                    }
                                }
                                catch (Exception oEx)
                                {
                                    string sMessage    = string.Empty;
                                    string sStackTrace = string.Empty;

                                    if (oEx.InnerException != null)
                                    {
                                        sMessage    = oEx.InnerException.Message;
                                        sStackTrace = oEx.InnerException.StackTrace;
                                    }
                                    else
                                    {
                                        sMessage    = oEx.Message;
                                        sStackTrace = oEx.StackTrace;
                                    }

                                    var mEx = new Exceptions(logging, sMessage, sStackTrace);
                                    if (mEx != null)
                                    {
                                        mEx.HandleException(mEx, logging);
                                    }
                                }
                            });

                            obj.Password = hashedPassword;
                            accountManager.AddAccount_ByHashedPassword(obj);
                        }
                        else
                        {
                            throw new MemberAccessException("This account already exists. Please try a different username");
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException("Dependency cannot be null. Please review the source code and contact site administrator for assistance");
                    }
                }
                catch (Exception ex)
                {
                    HasError = true;
                    _Error   = true;

                    if (ex.Message.Contains("Passwords do not match"))
                    {
                        ErrorMessage = "Passwords do not match";
                    }
                    else
                    {
                        ErrorMessage = "Invalid username or password";
                    }

                    if (ex.InnerException != null)
                    {
                        Message    = ex.InnerException.Message;
                        StackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        Message    = ex.Message;
                        StackTrace = ex.StackTrace;
                    }

                    var pEx = new Exceptions(logging, Message, StackTrace);
                    if (pEx != null)
                    {
                        pEx.HandleException(pEx, logging);
                    }
                }
            }).WaitUntilComplete(TimeSpan.FromSeconds(4), () =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    RegAnimate = false;

                    if (!_Error)
                    {
                        if (navigation != null)
                        {
                            navigation.GoBackAsync(true);
                        }
                    }
                    else
                    {
                        dialogue.ShowAlert("mmm...Something went wrong", Message);
                    }
                });
            });
        }
Exemple #17
0
        public async void Login()
        {
            Animate      = true;
            Instructions = "Validating Identity";
            bool _Failure = false;

            //Diagnostics
            string Message    = string.Empty;
            string StackTrace = string.Empty;

            await Task.Run(() =>
            {
                try
                {
                    //Place base code here
                    //Authenticate Site User here
                    if (string.IsNullOrWhiteSpace(Username))
                    {
                        throw new ArgumentNullException("Username cannot be empty. Please try again");
                    }
                    if (string.IsNullOrWhiteSpace(Password))
                    {
                        throw new ArgumentNullException("Password cannot be empty. Please try again");
                    }

                    if (accountManager != null)
                    {
                        //Apple Test Account
                        var hasher         = new PasswordEncoder();
                        var hashedPassword = hasher.Encode(Password, EncryptType.SHA_512);
                        if (accountManager.AuthenticateSiteUser_ByCredentials(Username, hashedPassword))
                        {
                            var curr = accountManager.GetSiteUser_ByUsername <Account>(Username);
                            Constants.InMemory_ContactID = curr.Contact_ID_Ref;

                            #region Save Credentials to Keychain if Remember me is Enabled
                            var credentialsStore = Xamarin.Auth.AccountStore.Create();
                            var AccountDetails   = new Xamarin.Auth.Account();
                            AccountDetails.Properties.Clear();

                            if (RememberMe)
                            {
                                AccountDetails.Username = Username;
                                AccountDetails.Properties.Add("RememberMe", "true");
                            }
                            else
                            {
                                AccountDetails.Username = Username;
                                AccountDetails.Properties.Add("RememberMe", "false");
                            }

                            credentialsStore.FindAccountsForService(Credentials_Service).ToList().Clear();
                            credentialsStore.Save(AccountDetails, Credentials_Service);
                            #endregion

                            try
                            {
                                var contacts = contactStore.Get_ContactsFromStore <Contact>();
                                if (contacts != null)
                                {
                                    if (contactManager != null)
                                    {
                                        var QueryContacts = contactManager.Get_Contacts_ByUserID <Contact>(curr.Contact_ID_Ref);
                                        contacts.ForEach(w =>
                                        {
                                            //Add Contact to the contact store for the particular account
                                            if (QueryContacts.SingleOrDefault(i => i.Contact_ID == w.Contact_ID && i.User_ID == curr.Contact_ID_Ref) == null)
                                            {
                                                w.Sys_Creation    = DateTime.Now;
                                                w.Sys_Transaction = DateTime.Now;

                                                w.Contact_ID = contactManager.Get_NewContactID();
                                                w.User_ID    = curr.Contact_ID_Ref;
                                                w.Mobile     = curr.Mobile;

                                                //Add Contacts to Table
                                                if (contactManager != null)
                                                {
                                                    contactManager.AddContact_ByDetails(w);
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                            catch (Exception eX)
                            {
                                string _Message    = string.Empty;
                                string _StackTrace = string.Empty;
                                if (eX.InnerException != null)
                                {
                                    _Message    = eX.InnerException.Message;
                                    _StackTrace = eX.InnerException.StackTrace;
                                }
                                else
                                {
                                    _Message    = eX.Message;
                                    _StackTrace = eX.StackTrace;
                                }

                                var mEx = new Exceptions(logging, _Message, _StackTrace);
                                if (mEx != null)
                                {
                                    mEx.HandleException(mEx, logging);
                                }
                            }

                            try
                            {
                                ////// Query Contacts and Music
                                var music = musicStore.GetMusic_Collection <Music>();
                                if (music != null)
                                {
                                    if (musicManager != null)
                                    {
                                        var QueryMusic = musicManager.GetMusicCollection_ByContactID <Music>(curr.Contact_ID_Ref);
                                        music.ForEach(w =>
                                        {
                                            if (QueryMusic.SingleOrDefault(i => i.User_ID == curr.Contact_ID_Ref) == null)
                                            {
                                                w.Sys_Creation    = DateTime.Now;
                                                w.Sys_Transaction = DateTime.Now;
                                                w.User_ID         = curr.Contact_ID_Ref;

                                                //Add Music to Table
                                                if (musicManager != null)
                                                {
                                                    musicManager.AddMusic(w);
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                            catch (Exception mX)
                            {
                                string _Message    = string.Empty;
                                string _StackTrace = string.Empty;
                                if (mX.InnerException != null)
                                {
                                    _Message    = mX.InnerException.Message;
                                    _StackTrace = mX.InnerException.StackTrace;
                                }
                                else
                                {
                                    _Message    = mX.Message;
                                    _StackTrace = mX.StackTrace;
                                }

                                var mEx = new Exceptions(logging, _Message, _StackTrace);
                                if (mEx != null)
                                {
                                    mEx.HandleException(mEx, logging);
                                }
                            }
                        }
                        else
                        {
                            //Check Cloud Service for the Site user's membership and generate an account locally
                            if (Username.Equals("apple", StringComparison.OrdinalIgnoreCase) && Password.Equals("password", StringComparison.OrdinalIgnoreCase))
                            {
                                //Generate Account
                                Account obj              = new Account();
                                obj.Contact_ID_Ref       = Guid.NewGuid().ToString();
                                obj.FirstName            = CultureInfo.CurrentCulture.TextInfo.ToTitleCase("Apple");
                                obj.LastName             = CultureInfo.CurrentCulture.TextInfo.ToTitleCase("Inc");
                                obj.SiteUser_DisplayName = $"{ obj.FirstName } { obj.LastName }";

                                obj.Sys_Creation    = DateTime.Now;
                                obj.Sys_Transaction = DateTime.Now;

                                //Has the passwords on account generation and on login
                                obj.Username = Username;
                                obj.Password = hashedPassword;

                                obj.Mobile = "";
                                obj.Work   = "";
                                obj.Email  = Username;
                                obj.Home   = "";

                                Constants.InMemory_ContactID = obj.Contact_ID_Ref;
                                accountManager.AddAccount_ByHashedPassword(obj);
                            }
                            else
                            {
                                DataVaultAccountServiceClient accountsClient = new DataVaultAccountServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.AccountsInSecureUrl));

                                var dataClient = accountsClient._Login_AccountForUserCredentials(Username, Password);
                                if (dataClient.SiteUser != null)
                                {
                                    var curr = dataClient.SiteUser;
                                    Constants.InMemory_ContactID = curr.User_ID;

                                    //Generate Account
                                    Account obj              = new Account();
                                    obj.Contact_ID_Ref       = curr.User_ID;
                                    obj.FirstName            = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(curr.First_Name);
                                    obj.LastName             = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(curr.Last_Name);
                                    obj.SiteUser_DisplayName = $"{ obj.FirstName } { obj.LastName }";

                                    obj.Sys_Creation    = DateTime.Now;
                                    obj.Sys_Transaction = DateTime.Now;

                                    //Has the passwords on account generation and on login
                                    obj.Username = Username;
                                    obj.Password = hashedPassword;

                                    obj.Mobile = curr.Mobile;
                                    obj.Work   = curr.Work;
                                    obj.Email  = Username;
                                    obj.Home   = curr.Home;
                                    obj.Avatar = curr.Avatar;

                                    accountManager.AddAccount_ByHashedPassword(obj); //Add account to local store

                                    #region Save Credentials to Keychain if Remember me is Enabled
                                    var credentialsStore = Xamarin.Auth.AccountStore.Create();
                                    var AccountDetails   = new Xamarin.Auth.Account();
                                    AccountDetails.Properties.Clear();

                                    if (RememberMe)
                                    {
                                        AccountDetails.Username = Username;
                                        AccountDetails.Properties.Add("RememberMe", "true");
                                    }
                                    else
                                    {
                                        AccountDetails.Username = Username;
                                        AccountDetails.Properties.Add("RememberMe", "false");
                                    }

                                    credentialsStore.Save(AccountDetails, Credentials_Service);
                                    #endregion

                                    try
                                    {
                                        var contacts = contactStore.Get_ContactsFromStore <Contact>();
                                        if (contacts != null)
                                        {
                                            if (contactManager != null)
                                            {
                                                var QueryContacts = contactManager.Get_Contacts_ByUserID <Contact>(curr.User_ID);
                                                contacts.ForEach(w =>
                                                {
                                                    //Add Contact to the contact store for the particular account
                                                    if (QueryContacts.SingleOrDefault(i => i.Contact_ID == w.Contact_ID && i.User_ID == curr.User_ID) == null)
                                                    {
                                                        w.Sys_Creation    = DateTime.Now;
                                                        w.Sys_Transaction = DateTime.Now;

                                                        w.Contact_ID = contactManager.Get_NewContactID();
                                                        w.User_ID    = curr.User_ID;

                                                        //Add Contacts to Table
                                                        if (contactManager != null)
                                                        {
                                                            contactManager.AddContact_ByDetails(w);
                                                        }
                                                    }
                                                });
                                            }
                                        }

                                        var music = musicStore.GetMusic_Collection <Music>();

                                        // Query Contacts and Music
                                        if (music != null)
                                        {
                                            if (musicManager != null)
                                            {
                                                var QueryMusic = musicManager.GetMusicCollection_ByContactID <Music>(curr.User_ID);
                                                music.ForEach(w =>
                                                {
                                                    if (QueryMusic.SingleOrDefault(i => i.User_ID == curr.User_ID) == null)
                                                    {
                                                        w.Sys_Creation    = DateTime.Now;
                                                        w.Sys_Transaction = DateTime.Now;
                                                        w.User_ID         = curr.User_ID;

                                                        //Add Music to Table
                                                        if (musicManager != null)
                                                        {
                                                            musicManager.AddMusic(w);
                                                        }
                                                    }
                                                });
                                            }
                                        }
                                    }
                                    catch (Exception eX)
                                    {
                                        string oMessage    = string.Empty;
                                        string oStackTrace = string.Empty;

                                        if (eX.InnerException != null)
                                        {
                                            oMessage    = eX.InnerException.Message;
                                            oStackTrace = eX.InnerException.StackTrace;
                                        }
                                        else
                                        {
                                            oMessage    = eX.Message;
                                            oStackTrace = eX.StackTrace;
                                        }

                                        var mEx = new Exceptions(logging, oMessage, oStackTrace);
                                        if (mEx != null)
                                        {
                                            mEx.HandleException(mEx, logging);
                                        }
                                    }
                                }
                                else
                                {
                                    throw new MemberAccessException("Authentication failure. The credentials you have provided are not valid. Please register an account");
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException("iOC Dependency is null. Please contact site administrator for assistance");
                    }
                }
                catch (Exception ex)
                {
                    HasError = true;
                    _Failure = true;

                    if (ex.InnerException != null)
                    {
                        Message    = ex.InnerException.Message;
                        StackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        Message    = ex.Message;
                        StackTrace = ex.StackTrace;
                    }

                    var mEx = new Exceptions(logging, Message, StackTrace);
                    if (mEx != null)
                    {
                        mEx.HandleException(mEx, logging);
                    }
                }
            }).ContinueWith((e) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Animate = false;

                    if (_Failure)
                    {
                        //Output a dialogue here
                        if (dialogue != null)
                        {
                            dialogue.ShowAlert("mmm...Something went wrong", Message);
                        }
                    }
                    else
                    {
                        if (this.navigation != null)
                        {
                            this.navigation.NavigateToViewModelAsync <HomeViewModel>(true);
                        }
                    }
                });
            });
        }