Exemple #1
0
        public void AddToHistory(InternalLoginInfo item)
        {
            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }

                InternalLoginInfoHistory hItem = InternalLoginInfoHistory.NewHistoryItem(item, Manager.GetPerson(UC.CurrentUserID), UC.IpAddress, UC.ProxyIpAddress);

                Manager.SaveOrUpdate(hItem);
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex) {
                if (!isInTransaction && Manager.IsInTransaction())
                {
                    Manager.RollBack();
                }
            }
        }
        public void Authenticate(String login, String password)
        {
            InternalLoginInfo user = InternalService.GetAuthenticatedUser(login, password);

            if (user == null || user.Person == null)
            {
                View.DisplayInvalidCredentials();
            }
            else if (!user.isEnabled || user.Person.isDisabled)
            {
                View.DisplayAccountDisabled();
            }
            else
            {
                Boolean isExpired = InternalService.ExpiredPassword(user.Person);
                InternalAuthenticationProvider provider = InternalService.GetActiveProvider();
                InternalService.UpdateUserAccessTime(user.Person);
                if ((user.Person.AcceptPolicy || !PolicyService.UserHasPolicyToAccept(user.Person)) && !isExpired)
                {
                    View.LogonUser(user.Person, ((provider != null) ? provider.Id : (long)0), RootObject.InternalLogin(View.AllowAdminAccess), true, CurrentManager.GetUserDefaultIdOrganization(user.Person.Id));
                }
                else if (isExpired)
                {
                    View.DisplayMustEditPassword(user.Person.Id, provider.Id);
                }
                else
                {
                    View.DisplayPrivacyPolicy(user.Person.Id, provider.Id, RootObject.InternalLogin(View.AllowAdminAccess), true);
                }
            }
        }
        public void RenewPassword(int IdUser)
        {
            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout();
            }
            else
            {
                dtoFilters filters     = View.GetCurrentFilters;
                String     newPassword = "";
                Person     person      = CurrentManager.GetPerson(IdUser);
                if (person != null)
                {
                    InternalLoginInfo internalLogin = Service.RenewPassword(IdUser, ref newPassword);

                    if (!String.IsNullOrEmpty(newPassword) && internalLogin != null)
                    {
                        if (View.SendMail(internalLogin, newPassword))
                        {
                            View.DisplayPasswordChanged(person.SurnameAndName);
                        }
                        else
                        {
                            View.DisplayUnableToSendPassword(person.SurnameAndName);
                        }
                    }
                    else
                    {
                        View.DisplayUnableToChangePassword(person.SurnameAndName);
                    }
                }
                SearchProfiles(filters.PageIndex, filters.PageSize);
            }
        }
Exemple #4
0
        public InternalLoginInfo RenewPassword(Person person, EditType editBy, ref String newPassword)
        {
            InternalLoginInfo loginInfo = null;

            try
            {
                Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor();
                if (person != null)
                {
                    Manager.BeginTransaction();
                    Person currentUser = Manager.GetPerson(UC.CurrentUserID);
                    loginInfo = (from li in Manager.GetIQ <InternalLoginInfo>() where li.Person == person select li).Skip(0).Take(1).ToList().FirstOrDefault();

                    if (loginInfo != null)
                    {
                        newPassword        = lm.Comol.Core.DomainModel.Helpers.RandomKeyGenerator.GenerateRandomKey(6, 10, true, true, false);
                        loginInfo.Password = helper.Encrypt(newPassword);
                        loginInfo.UpdateMetaInfo(Manager.GetPerson(UC.CurrentUserID), UC.IpAddress, UC.ProxyIpAddress);
                        loginInfo.ResetType = editBy;
                        Manager.SaveOrUpdate(loginInfo);
                        AddToHistory(loginInfo);
                    }
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                loginInfo = null;
            }
            return(loginInfo);
        }
Exemple #5
0
        //public String RenewPassword(String login)
        //{
        //    String newPassword = "";
        //    try
        //    {
        //        InternalLoginInfo info  = (from i in this.Manager.GetIQ<InternalLoginInfo>()
        //                  where i.Login == login
        //                  select i).Skip(0).Take(1).ToList().FirstOrDefault();
        //        newPassword = RenewPassword(info);
        //    }
        //    catch (Exception ex)
        //    {
        //        Manager.RollBack();
        //        newPassword = "";
        //    }
        //    return newPassword;
        //}
        public String RenewPassword(InternalLoginInfo userInfo, Person modifyBy, EditType editBy)
        {
            String newPassword = "";

            try
            {
                Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor();
                if (userInfo != null)
                {
                    Manager.BeginTransaction();
                    Person currentUser = Manager.GetPerson(UC.CurrentUserID);
                    if (currentUser == null && UC.CurrentUserID == 0)
                    {
                        currentUser = userInfo.Person;
                    }
                    newPassword       = lm.Comol.Core.DomainModel.Helpers.RandomKeyGenerator.GenerateRandomKey(6, 10, true, true, false);
                    userInfo.Password = helper.Encrypt(newPassword);
                    userInfo.UpdateMetaInfo(modifyBy, UC.IpAddress, UC.ProxyIpAddress);
                    userInfo.ResetType = editBy;
                    Manager.SaveOrUpdate(userInfo);
                    AddToHistory(userInfo);
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                newPassword = "";
            }
            return(newPassword);
        }
Exemple #6
0
        public ProfilerError UpdateInternalProfile(InternalLoginInfo loginInfo, Person person, String login)
        {
            ProfilerError message = VerifyProfileInfo(person, login);

            if (message == ProfilerError.none)
            {
                try
                {
                    Manager.BeginTransaction();
                    loginInfo.UpdateMetaInfo(Manager.GetPerson(UC.CurrentUserID), UC.IpAddress, UC.ProxyIpAddress);
                    loginInfo.Deleted = BaseStatusDeleted.None;
                    loginInfo.Login   = login;
                    Manager.SaveOrUpdate(loginInfo);
                    AddToHistory(loginInfo);
                    Manager.Commit();
                    message = ProfilerError.none;
                }
                catch (Exception ex)
                {
                    Manager.RollBack();
                    message = ProfilerError.internalError;
                }
            }
            return(message);
        }
        private Boolean AddAuthentication(Person person, dtoBaseProfile profile, dtoImportSettings settings, ProfileAttributesRow row, AuthenticationProvider provider)
        {
            Boolean result = false;

            if (provider.ProviderType == AuthenticationProviderType.Internal)
            {
                InternalLoginInfo info = InternalService.GenerateUserInfo(person, profile.Login, profile.Password, (InternalAuthenticationProvider)provider, false);
                result = (info != null);
            }
            else
            {
                dtoExternalCredentials credentials = new dtoExternalCredentials();
                if (lm.Comol.Core.DomainModel.PermissionHelper.CheckPermissionSoft((int)provider.IdentifierFields, (int)IdentifierField.longField))
                {
                    long identifierLong = 0;
                    long.TryParse(row.GetCellValue(ProfileAttributeType.externalId), out identifierLong);
                    credentials.IdentifierLong = identifierLong;
                }
                if (lm.Comol.Core.DomainModel.PermissionHelper.CheckPermissionSoft((int)provider.IdentifierFields, (int)IdentifierField.stringField))
                {
                    credentials.IdentifierString = row.GetCellValue(ProfileAttributeType.externalId);
                }

                if (UrlService.VerifyDuplicateExternalLoginInfo(person, provider, credentials) == ProfilerError.none)
                {
                    ExternalLoginInfo externaLogin = UrlService.AddExternalProfile(person, provider, credentials);
                    result = (externaLogin != null);
                }
            }
            return(result);
        }
Exemple #8
0
        //private TokenCheckPrevious


        private string TokenGenerate(InternalLoginInfo user, string deviceId, Domain.TokenType type)
        {
            if (user == null || user.Person == null)
            {
                return("");
            }

            if (String.IsNullOrEmpty(deviceId))
            {
                deviceId = DefaultDeviceId;
            }

            Domain.MobiToken token = Manager.GetAll <Domain.MobiToken>(mt => mt.PersonId == user.Person.Id && mt.DeviceId == deviceId)
                                     .Skip(0)
                                     .Take(1)
                                     .FirstOrDefault();

            if (token == null)
            {
                token      = new Domain.MobiToken();
                token.Type = type;
            }
            else
            {
                //token.Type = type;
            }

            token.CreateOn = DateTime.Now;
            token.PersonId = user.Person.Id;
            token.Token    = System.Guid.NewGuid().ToString();
            token.DeviceId = deviceId;


            try
            {
                if (!Manager.IsInTransaction())
                {
                    Manager.BeginTransaction();
                }

                Manager.SaveOrUpdate <Domain.MobiToken>(token);

                Manager.Commit();
            }
            catch (Exception)
            {
                if (Manager.IsInTransaction())
                {
                    Manager.RollBack();
                }
                return("");
            }

            ClearOldToken(user.Person.Id, type, token.Id, deviceId);

            return(token.Token);
        }
Exemple #9
0
        public InternalLoginInfo AddUserInfo(String login, String password, int idPerson, DateTime passwordExpiresOn, InternalAuthenticationProvider provider)
        {
            InternalLoginInfo userInfo = null;

            try
            {
                Person currentUser = Manager.GetPerson(UC.CurrentUserID);
                Person creator     = Manager.GetPerson(idPerson);
                if (currentUser == null)
                {
                    currentUser = creator;
                }
                if (provider != null && creator != null)
                {
                    Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor();
                    Manager.BeginTransaction();
                    userInfo = new InternalLoginInfo();
                    userInfo.CreateMetaInfo(currentUser, UC.IpAddress, UC.ProxyIpAddress);
                    userInfo.PasswordExpiresOn = passwordExpiresOn;
                    userInfo.Deleted           = BaseStatusDeleted.None;
                    userInfo.isEnabled         = true;
                    userInfo.Provider          = provider;
                    userInfo.Login             = login;
                    userInfo.Password          = helper.Encrypt(password);
                    userInfo.Person            = creator;
                    if (creator.IdDefaultProvider == 0 || String.IsNullOrEmpty(creator.FirstLetter))
                    {
                        //// TEMPORANEO
                        //creator.Login = login;
                        //creator.Password=userInfo.Password;
                        //// TEMPORANEO
                        if (creator.IdDefaultProvider == 0)
                        {
                            creator.IdDefaultProvider = provider.Id;
                        }
                        if (String.IsNullOrEmpty(creator.FirstLetter))
                        {
                            creator.FirstLetter = creator.Surname[0].ToString().ToLower();
                        }
                        Manager.SaveOrUpdate(creator);
                    }
                    Manager.SaveOrUpdate(userInfo);
                    AddToHistory(userInfo);
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                userInfo = null;
            }
            return(userInfo);
        }
Exemple #10
0
        public InternalLoginInfo GetLoginInfo(Person person)
        {
            InternalLoginInfo info = null;

            try
            {
                info = (from i in this.Manager.GetIQ <InternalLoginInfo>()
                        where i.Person == person && i.Deleted == BaseStatusDeleted.None
                        select i).Skip(0).Take(1).ToList().FirstOrDefault();
            }
            catch (Exception ex)
            {
            }
            return(info);
        }
Exemple #11
0
        public InternalLoginInfo GetAuthenticatedUser(String login, String password)
        {
            InternalLoginInfo result = null;

            try
            {
                Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor();
                result = (from i in this.Manager.GetIQ <InternalLoginInfo>()
                          where i.Login == login && i.Password == helper.Encrypt(password) && i.Deleted == BaseStatusDeleted.None
                          select i).Skip(0).Take(1).ToList().FirstOrDefault();
            }
            catch (Exception ex)
            {
                result = null;
            }
            return(result);
        }
        public void RenewPassword(int IdUser)
        {
            if (UserContext.isAnonymous)
            {
                View.DisplayWorkinkSessionTimeout();
            }
            else
            {
                String            newPassword   = "";
                InternalLoginInfo internalLogin = Service.RenewPassword(IdUser, ref newPassword);

                if (!String.IsNullOrEmpty(newPassword) && internalLogin != null)
                {
                    View.SendMail(internalLogin, newPassword);
                }
            }
        }
Exemple #13
0
        public InternalLoginInfo SetPassword(Person person, String newPassword, Boolean isOneTimePassword)
        {
            InternalLoginInfo userInfo = null;

            try
            {
                InternalAuthenticationProvider provider = (from p in Manager.GetIQ <InternalAuthenticationProvider>()
                                                           where p.IsEnabled && p.Deleted == BaseStatusDeleted.None
                                                           select p).Skip(0).Take(1).ToList().FirstOrDefault();

                userInfo = (from i in this.Manager.GetIQ <InternalLoginInfo>()
                            where i.Person == person && i.Deleted == BaseStatusDeleted.None
                            select i).Skip(0).Take(1).ToList().FirstOrDefault();
                Person setUser = Manager.GetPerson(UC.CurrentUserID);
                Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor();
                if (userInfo == null || setUser == null)
                {
                    throw new UnknownItemException();
                }
                else
                {
                    Manager.BeginTransaction();
                    userInfo.UpdateMetaInfo(setUser, UC.IpAddress, UC.ProxyIpAddress);
                    userInfo.Password  = helper.Encrypt(newPassword);
                    userInfo.ResetType = (isOneTimePassword) ? EditType.oneTime : EditType.admin;
                    if (provider != null && provider.ChangePasswordAfterDays > 0)
                    {
                        userInfo.PasswordExpiresOn = DateTime.Now.AddDays(provider.ChangePasswordAfterDays);
                    }
                    AddToHistory(userInfo);
                    Manager.Commit();
                }
            }
            catch (UnknownItemException uEx)
            {
                userInfo = null;
                throw uEx;
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                userInfo = null;
            }
            return(userInfo);
        }
Exemple #14
0
        public Boolean ExpiredPassword(Person person)
        {
            Boolean expired = false;

            try
            {
                InternalLoginInfo info = (from i in this.Manager.GetIQ <InternalLoginInfo>()
                                          where i.Person == person && i.Deleted == BaseStatusDeleted.None
                                          select i).Skip(0).Take(1).ToList().FirstOrDefault();
                if (info != null)
                {
                    expired = ((info.ResetType == EditType.retrieve || info.ResetType == EditType.oneTime || info.ResetType == EditType.reset) || (info.PasswordExpiresOn.HasValue && info.PasswordExpiresOn.Value < DateTime.Now));
                }
            }
            catch (Exception ex)
            {
            }
            return(expired);
        }
        public void SaveInternalProvider(String login)
        {
            ProfilerError message     = ProfilerError.internalError;
            long          idLoginInfo = View.CurrentIdLoginInfo;

            if (idLoginInfo == 0)
            {
                String            password  = "";
                InternalLoginInfo loginInfo = null;
                message = Service.AddInternalLogin(View.idProfile, login, ref password, ref loginInfo);
                if (message == ProfilerError.none && !string.IsNullOrEmpty(password) && loginInfo != null)
                {
                    View.SendMail(loginInfo, password);
                }
                SetupOtherProviders();
            }
            else
            {
                message = Service.UpdateInternalProfile(idLoginInfo, View.idProfile, login);
            }
            if (message == ProfilerError.none)
            {
                if (idLoginInfo == 0)
                {
                    Person person = CurrentManager.GetPerson(View.idProfile);
                    if (person != null)
                    {
                        View.idDefaultProvider = person.IdDefaultProvider;
                    }
                }
                LoadAuthenticationItems();
            }
            else if (message == ProfilerError.loginduplicate)
            {
                View.DisplayProfilerInternalError(message);
            }
            else
            {
                View.DisplayError(message);
            }
        }
 public void SaveInternalPassword(String password, Boolean isOneTimePassword)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplayWorkinkSessionTimeout();
     }
     else
     {
         long idLoginInfo = View.CurrentIdLoginInfo;
         if (idLoginInfo > 0)
         {
             Person            person    = CurrentManager.GetPerson(View.idProfile);
             InternalLoginInfo loginInfo = Service.SetPassword(person, password, isOneTimePassword);
             if (loginInfo != null)
             {
                 View.SendMail(loginInfo, password);
             }
         }
         LoadAuthenticationItems();
     }
 }
        private void MoveFromStepInternalCredentials()
        {
            dtoInternalCredentials credentials = View.GetInternalCredentials;
            InternalLoginInfo      info        = InternalService.GetAuthenticatedUser(credentials.Login, credentials.Password);

            if (info == null || info.Person == null)
            {
                View.DisplayInvalidCredentials();
            }
            else
            {
                UrlAuthenticationProvider provider = GetProvider();
                if (provider == null)
                {
                    View.DisplayInternalCredentialsMessage(ProfileSubscriptionMessage.ProviderUnknown);
                }
                else
                {
                    ExternalLoginInfo account = UrlService.AddFromInternalAccount(info, provider, View.UrlIdentifierValue);
                    if (account == null)
                    {
                        View.DisplayInternalCredentialsMessage(ProfileSubscriptionMessage.UnableToConnectToInternalProvider);
                    }
                    else if (account != null && account.Person.isDisabled)
                    {
                        View.LoadRegistrationMessage(ProfileSubscriptionMessage.AccountDisabled);
                    }
                    else if (PolicyService.UserHasPolicyToAccept(account.Person))
                    {
                        View.IdProfile = account.Person.Id;
                        InternalService.UpdateUserAccessTime(account.Person);
                        View.DisplayPrivacyPolicy(account.Person.Id, provider.Id, provider.RemoteLoginUrl, false);
                    }
                    else
                    {
                        View.LogonUser(account.Person, View.idProvider, provider.RemoteLoginUrl, false, CurrentManager.GetUserDefaultIdOrganization(account.Person.Id));
                    }
                }
            }
        }
        public void RetrievePassword(string mail)
        {
            InternalLoginInfo user = InternalService.FindUserByMail(mail);

            if (user == null || user.Person == null)
            {
                View.DisplayRetrievePasswordUnknownLogin();
            }
            else
            {
                String newPassword = InternalService.RenewPassword(user, user.Person, EditType.retrieve);
                if (String.IsNullOrEmpty(newPassword))
                {
                    View.DisplayRetrievePasswordError();
                }
                else
                {
                    View.SendMail(user, newPassword, CurrentManager.GetAllLanguages().Where(l => l.Id == user.Person.LanguageID).FirstOrDefault());
                    View.GotoInternalLogin();
                }
            }
        }
 public void SetPassword(long idLoginInfo)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplayWorkinkSessionTimeout();
     }
     else
     {
         InternalLoginInfo loginInfo = CurrentManager.Get <InternalLoginInfo>(idLoginInfo);
         if (loginInfo != null && loginInfo.Person != null)
         {
             View.CurrentIdProvider = 0;
             if (typeof(InternalLoginInfo) == loginInfo.GetType())
             {
                 View.EditInternalUserPassword(idLoginInfo, loginInfo.Login, loginInfo.Person.SurnameAndName, loginInfo.Person.Mail);
             }
         }
         else
         {
             LoadAuthenticationItems();
         }
     }
 }
Exemple #20
0
        //public Boolean EditPassword(String login, String oldPassword, String newPassword)
        //{
        //    Boolean result = false;
        //    try
        //    {
        //        Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor();
        //        InternalLoginInfo info  = (from i in this.Manager.GetIQ<InternalLoginInfo>()
        //                  where i.Login == login && i.Password == helper.Encrypt(oldPassword)
        //                  select i).Skip(0).Take(1).ToList().FirstOrDefault();
        //        if (info != null) {
        //            Manager.BeginTransaction();
        //            info.Password = helper.Encrypt(newPassword);
        //            info.UpdateMetaInfo(Manager.GetPerson(UC.CurrentUserID), UC.IpAddress, UC.ProxyIpAddress);
        //            Manager.SaveOrUpdate(info);
        //            result = true;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Manager.RollBack();
        //    }
        //    return result;
        //}
        public Boolean EditPassword(Person person, String oldPassword, String newPassword, Boolean mustEdit)
        {
            Boolean edited = false;

            try
            {
                InternalAuthenticationProvider provider = (from p in Manager.GetIQ <InternalAuthenticationProvider>()
                                                           where p.IsEnabled && p.Deleted == BaseStatusDeleted.None
                                                           select p).Skip(0).Take(1).ToList().FirstOrDefault();

                InternalLoginInfo info = (from i in this.Manager.GetIQ <InternalLoginInfo>()
                                          where i.Person == person && i.Deleted == BaseStatusDeleted.None
                                          select i).Skip(0).Take(1).ToList().FirstOrDefault();

                Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor();
                if (info == null)
                {
                    throw new UnknownItemException();
                }
                else if (info.Password != helper.Encrypt(oldPassword))
                {
                    throw new InvalidPasswordException();
                }
                else if (mustEdit && info.Password == helper.Encrypt(newPassword))
                {
                    throw new SamePasswordException();
                }
                else
                {
                    Manager.BeginTransaction();
                    info.UpdateMetaInfo(Manager.GetPerson((mustEdit) ? person.Id : UC.CurrentUserID), UC.IpAddress, UC.ProxyIpAddress);
                    info.Password  = helper.Encrypt(newPassword);
                    info.ResetType = (info.ModifiedBy == person || mustEdit) ? EditType.user : EditType.admin;
                    if (provider != null && provider.ChangePasswordAfterDays > 0)
                    {
                        info.PasswordExpiresOn = DateTime.Now.AddDays(provider.ChangePasswordAfterDays);
                    }
                    Manager.Commit();
                    AddToHistory(info);
                    edited = true;
                }
            }

            catch (SamePasswordException uEx)
            {
                throw uEx;
            }
            catch (UnknownItemException uEx) {
                throw uEx;
            }
            catch (InvalidPasswordException pEx)
            {
                throw pEx;
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                newPassword = "";
            }
            return(edited);
        }
 public ExternalLoginInfo AddFromInternalAccount(InternalLoginInfo internalAccount, UrlAuthenticationProvider provider, String externalString)
 {
     return(AddUserInfo(internalAccount.Person, internalAccount.Person, provider, externalString));
 }
Exemple #22
0
        public InternalLoginInfo GenerateUserInfo(Person person, String login, String password, InternalAuthenticationProvider provider, Boolean oneTimePassword)
        {
            InternalLoginInfo userInfo = null;

            try
            {
                Person currentUser = Manager.GetPerson(UC.CurrentUserID);
                if (currentUser == null)
                {
                    currentUser = person;
                }
                if (provider != null && person != null)
                {
                    Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor();
                    Manager.BeginTransaction();
                    if (!(from l in Manager.GetIQ <InternalLoginInfo>()
                          where l.Person == person && l.Deleted == BaseStatusDeleted.None && l.Provider == provider
                          select l.Id).Any())
                    {
                        userInfo = new InternalLoginInfo();
                        userInfo.CreateMetaInfo(currentUser, UC.IpAddress, UC.ProxyIpAddress);
                        userInfo.PasswordExpiresOn = (provider == null || provider.ChangePasswordAfterDays == 0) ? DateTime.MaxValue : DateTime.Now.AddDays(provider.ChangePasswordAfterDays);
                        userInfo.Deleted           = BaseStatusDeleted.None;
                        userInfo.isEnabled         = true;
                        userInfo.Provider          = provider;
                        userInfo.Login             = login;
                        userInfo.Password          = helper.Encrypt(password);
                        userInfo.Person            = person;
                        userInfo.ResetType         = (oneTimePassword) ? EditType.oneTime : EditType.admin;
                        if (person.IdDefaultProvider == 0 || String.IsNullOrEmpty(person.FirstLetter))
                        {
                            if (person.IdDefaultProvider == 0)
                            {
                                person.IdDefaultProvider = provider.Id;
                            }
                            if (String.IsNullOrEmpty(person.FirstLetter))
                            {
                                person.FirstLetter = person.Surname[0].ToString().ToLower();
                            }
                            Manager.SaveOrUpdate(person);
                        }

                        Manager.SaveOrUpdate(userInfo);
                        AddToHistory(userInfo);
                    }
                    else
                    {
                        userInfo = (from l in Manager.GetIQ <InternalLoginInfo>()
                                    where l.Person == person && l.Deleted == BaseStatusDeleted.None && l.Provider == provider
                                    select l).Skip(0).Take(1).ToList().FirstOrDefault();
                    }
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                userInfo = null;
            }
            return(userInfo);
        }