示例#1
0
        public static bool ControlToPasswordIsUsed(VeriBranchDataEntities entities, string password, long userID, short channelID)
        {
            short usedPasswordControl = ConfigurationParametersPresenter.GetParameter(ConfigurationParameterKeys.UsedPasswordControlType).ToShort(0);
            UsedPasswordControlTypeEnum passwordControlType = (UsedPasswordControlTypeEnum)usedPasswordControl;
            int usedPasswordControlValue = ConfigurationParametersPresenter.GetParameter(ConfigurationParameterKeys.UsedPasswordControlValue).ToInteger();

            if (usedPasswordControlValue != 0 && passwordControlType != UsedPasswordControlTypeEnum.Undefined)
            {
                List <string> passwordHistory = new List <string>();
                if (passwordControlType == UsedPasswordControlTypeEnum.Day)
                {
                    DateTime oldPinControlDate = DateTime.Now.AddDays(-1 * usedPasswordControlValue);
                    passwordHistory = entities.VpPasswordHistory.Where
                                          (q => q.UserID == userID &&
                                          q.ChannelID == channelID &&
                                          q.CreateDate > oldPinControlDate
                                          ).OrderByDescending(q => q.CreateDate).Select(q => q.Password).ToList();
                }
                else
                {
                    int usedControlCount = usedPasswordControlValue;
                    passwordHistory = (entities.VpPasswordHistory.Where
                                           (q => q.UserID == userID &&
                                           q.ChannelID == channelID).OrderByDescending(q => q.CreateDate).Select(q => q.Password).ToList().Take(usedControlCount).ToList());
                }
                if (passwordHistory != null && passwordHistory.Count > 0)
                {
                    return(passwordHistory.Contains(password));
                }
            }
            return(false);
        }
示例#2
0
        public void Execute(object requestMessage, ref object responseMessage, TransactionHeader transactionHeader)
        {
            //device already registered
            //no user registed with this id
            SoftTokenRegistrationRequest  request  = requestMessage as SoftTokenRegistrationRequest;
            SoftTokenRegistrationResponse response = responseMessage as SoftTokenRegistrationResponse;

            VpUser user = null;

            //verify userId, password, otp
            using (VeriBranchDataEntities dataEntities = new VeriBranchDataEntities())
            {
                user = dataEntities.VpUser.Where(obj => obj.UserName.Equals(request.CustomerId)).FirstOrDefault();
            }
            if (user == null)
            {
                throw new VPBusinessException("NoUserWithThisId");
            }

            // move the below method to Login Manager
            //VerifyUserIdPassword(request, response, transactionHeader);
            response.AuthrnticationSuccess = LoginManager.VerifyUserIdPassword(request.CustomerId, request.Password, transactionHeader);

            VerifyOTP(request, response, transactionHeader, user);
            VerifyCardAccountAndPin(request, response, transactionHeader, user);
            if (response.AuthrnticationSuccess)
            {
                VpOtpDevice device = new VpOtpDevice()
                {
                    CreateBy     = Convert.ToString(user.ID),
                    CreateDate   = DateTime.Now,
                    OtpType      = 4,
                    SerialNumber = request.DeviceId,
                    Status       = 2,
                    ModifyBy     = "",
                    ModifyDate   = DateTime.Now,
                };
                using (VeriBranchDataEntities dataEntities = new VeriBranchDataEntities())
                {
                    if (dataEntities.VpOtpDevice.Where(obj => obj.SerialNumber == request.DeviceId).Count() > 0)
                    {
                        throw new VPBusinessException("DeviceAlreadyRegistered");
                    }

                    dataEntities.VpOtpDevice.Add(device);
                    dataEntities.SaveChanges();
                    VPSoftTokenRegistration softTokenRegistration = new VPSoftTokenRegistration()
                    {
                        DeviceId   = device.ID,
                        Password   = HashHelper.Hash(request.STPassword, string.Empty, HashTypeEnum.Md5),
                        UserId     = user.ID,
                        Preference = request.UseFingerPrint.ToString(),
                    };
                    dataEntities.VPSoftTokenRegistration.Add(softTokenRegistration);
                    dataEntities.SaveChanges();
                }
            }
        }
示例#3
0
        public static void AddtoPasswordHistory(VeriBranchDataEntities entities, string password, long userID, short channelID)
        {
            VpPasswordHistory addedPin = new VpPasswordHistory();

            addedPin.Password   = password;
            addedPin.UserID     = userID;
            addedPin.ChannelID  = channelID;
            addedPin.CreateDate = DateTime.Now;
            addedPin.CreateBy   = "User";
            entities.VpPasswordHistory.Add(addedPin);
        }
示例#4
0
        private bool VerifyOTP(SoftTokenRegistrationRequest request, SoftTokenRegistrationResponse response, TransactionHeader transactionHeader, VpUser user)
        {
            using (VeriBranchDataEntities dataEntities = new VeriBranchDataEntities())
            {
                VpOtpHistory OTPHistory = dataEntities.VpOtpHistory.Where(obj => obj.UserID == user.ID).OrderByDescending(obj => obj.ID).FirstOrDefault();

                var hashedOTP = HashHelper.Hash(request.OTP, string.Empty, HashTypeEnum.Md5);
                if (OTPHistory != null && OTPHistory.OTP == hashedOTP)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
示例#5
0
 public static void AddLogonHistory(AuthenticationContext context, AuthenticationResult result)
 {
     if (context.UserID != 0)
     {
         VpUserLogonHistory history = new VpUserLogonHistory();
         history.UserID           = context.UserID;
         history.ChannelID        = context.ChannelID;
         history.InitialSessionID = context.InitialSessionID;
         history.IP          = context.ClientIp;
         history.LogonType   = (int)context.TransactionHeader.Customer.LogonType;
         history.LoginResult = (short)(result != null ? result.Result.GetHashCode() : LoginResultEnum.Undefined.GetHashCode());
         string logonBrowser = context.LogonBrowser;
         if (!string.IsNullOrEmpty(logonBrowser))
         {
             if (logonBrowser.Length > 255)
             {
                 logger.Error(string.Format("Max LogonBrowser length (255) is reached for following UserAgent : {0} \n InitialSessionId : {1} \n UserID: {2}", logonBrowser, context.InitialSessionID, context.UserID));
                 logonBrowser = logonBrowser.Substring(0, 255);
             }
         }
         if (string.IsNullOrEmpty(ConfigurationParametersPresenter.Instance["AllowedLoginTypesForLogonBrowserLogging"]) ||
             ConfigurationParametersPresenter.Instance["AllowedLoginTypesForLogonBrowserLogging"].Split(',').ToList().Contains(history.LoginResult.ToString()))
         {
             history.LogonBrowser = logonBrowser;
         }
         history.LoginDate           = DateTime.Now;
         history.IsLogonDeviceMobile = Utils.IsMobileBrowser(context.LogonBrowser);
         if (LoggingManager.AsyncLoggingEnabled && ConfigurationParametersPresenter.Instance["UserLogonHistoryAsyncLoggingEnabled"].ToBoolean())
         {
             QueueHelper.Enqueue(history, ConfigReader.DefaultLogMessageQueuePath);
         }
         else
         {
             using (VeriBranchDataEntities dataEntities = new VeriBranchDataEntities())
             {
                 dataEntities.VpUserLogonHistory.Add(history);
                 dataEntities.SaveChanges();
             }
         }
     }
 }
        public void Execute(object requestMessage, ref object responseMessage, TransactionHeader transactionHeader)
        {
            SoftTokenDeviceExistenceTransactionRequest  request  = requestMessage as SoftTokenDeviceExistenceTransactionRequest;
            SoftTokenDeviceExistenceTransactionResponse response = responseMessage as SoftTokenDeviceExistenceTransactionResponse;

            using (VeriBranchDataEntities dataEntities = new VeriBranchDataEntities())
            {
                var result = dataEntities.VPSoftTokenRegistration.Where(x => x.VpOtpDevice.SerialNumber.Equals(request.DeviceId)).ToList();

                if (result != null && result.Count > 0)
                {
                    response.IsExisting     = true;
                    response.UserId         = result[0].UserId;
                    response.UseFingerPrint = Convert.ToBoolean(result[0].Preference);
                }
                else
                {
                    response.IsExisting = false;
                }
            }
        }
        public void Execute(object requestMessage, ref object responseMessage, TransactionHeader transactionHeader)
        {
            long userID = transactionHeader.Customer.UserId;

            SoftTokenSelectAuthenticationRequest  request  = requestMessage as SoftTokenSelectAuthenticationRequest;
            SoftTokenSelectAuthenticationResponse response = responseMessage as SoftTokenSelectAuthenticationResponse;
            VpOtpHistory otpHistory = null;

            string password = request.Password;

            try
            {
                using (VeriBranchDataEntities context = new VeriBranchDataEntities())
                {
                    otpHistory = context.VpOtpHistory.Where(obj => obj.UserID == userID).OrderByDescending(obj => obj.ID).FirstOrDefault();

                    if (otpHistory != null)
                    {
                        string decryptedOTP = string.Empty;
                        if (ConfigurationParametersPresenter.GetParameter(LoginConstants.FlowItemType.OTPEncryptionEnabledKey) != null)
                        {
                            // these must be replaced by fetching certificate from store
                            string privateKey = Convert.ToString(ConfigurationParametersPresenter.GetParameter(LoginConstants.FlowItemType.EncryptionPrivateKey));
                            int    keySize    = Convert.ToInt32(ConfigurationParametersPresenter.GetParameter(LoginConstants.FlowItemType.EncryptionKeySizeKey));
                            decryptedOTP = Encryption.DecryptString(otpHistory.EncryptedOTP, privateKey);
                        }

                        if (decryptedOTP == password)
                        {
                            response.Status = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.Status = false;
            }
        }
 public static void SetLogon(TransactionHeader transactionHeader)
 {
     using (VeriBranchDataEntities dataEntities = new VeriBranchDataEntities())
     {
         //VpLogon logon = dataEntities.VpLogon.Where(dataEntity => dataEntity.CustomerUserCode == transactionHeader.Customer.CustomerUserCode).SingleOrDefault();
         //if (logon == null)
         //{
         //    logon = new VpLogon();
         //    logon.CustomerUserCode = transactionHeader.Customer.CustomerUserCode;
         //    logon.ChannelId = transactionHeader.Channel.ChannelType.GetHashCode();
         //    logon.LastLogonDate = DateTime.Now;
         //    logon.SessionId = transactionHeader.Session.Sessionid;
         //    dataEntities.VpLogon.AddObject(logon);
         //}
         //else
         //{
         //    logon.LastLogonDate = DateTime.Now;
         //    logon.SessionId = transactionHeader.Session.Sessionid;
         //}
         //dataEntities.SaveChanges();
     }
 }
        public void Execute(object requestMessage, ref object responseMessage, TransactionHeader transactionHeader)
        {
            GenerateSoftTokenRequest  request  = requestMessage as GenerateSoftTokenRequest;
            GenerateSoftTokenResponse response = responseMessage as GenerateSoftTokenResponse;
            VpOtpHistory otpHistory            = null;

            string hashedPassword = string.Empty;

            using (VeriBranchDataEntities context = new VeriBranchDataEntities())
            {
                var device = context.VpOtpDevice.Where(obj => obj.SerialNumber == request.DeviceId).FirstOrDefault();
                if (device == null)
                {
                    throw new VPBusinessException("DeviceNotExistException");
                }
                long userId = Convert.ToInt32(device.CreateBy);

                if (!string.IsNullOrEmpty(request.Password))
                {
                    hashedPassword = HashHelper.Hash(request.Password, string.Empty, HashTypeEnum.Md5);
                    if (context.VPSoftTokenRegistration.Where(obj => obj.UserId == userId && obj.Password == hashedPassword).FirstOrDefault() != null)
                    {
                        otpHistory = context.VpOtpHistory.Where(obj => obj.UserID == userId && obj.ExpireTime >= DateTime.Now).OrderByDescending(obj => obj.ID).FirstOrDefault();
                    }
                    else
                    {
                        throw new VPBusinessException("WrongPassword");
                    }
                }
                else if (string.IsNullOrEmpty(request.Password) && request.IsAuthenticatedWithFingerPrint)
                {
                    string autoPass = request.DeviceId + "true" + request.DeviceId; // 1 because AutoPassword should have set IsAuthenticatedWithFingerPrint
                    if (autoPass.Equals(request.AutoPassword))
                    {
                        otpHistory = context.VpOtpHistory.Where(obj => obj.UserID == userId && obj.ExpireTime >= DateTime.Now).OrderByDescending(obj => obj.ID).FirstOrDefault();
                    }
                    else
                    {
                        throw new VPBusinessException("WrongPassword");
                    }
                }
                else
                {
                    throw new VPBusinessException("WrongPassword");
                }
            }
            if (otpHistory != null || string.IsNullOrEmpty(otpHistory.EncryptedOTP))
            {
                string decryptedOTP = string.Empty;
                if (ConfigurationParametersPresenter.GetParameter(LoginConstants.FlowItemType.OTPEncryptionEnabledKey) != null)
                {
                    // these must be replaced by fetching certificate from store
                    string privateKey = Convert.ToString(ConfigurationParametersPresenter.GetParameter(LoginConstants.FlowItemType.EncryptionPrivateKey));
                    int    keySize    = Convert.ToInt32(ConfigurationParametersPresenter.GetParameter(LoginConstants.FlowItemType.EncryptionKeySizeKey));
                    decryptedOTP = Encryption.DecryptString(otpHistory.EncryptedOTP, privateKey);
                }
                response.OTP = decryptedOTP;
            }
            else
            {
                response.OTP = VeriBranch.Utilities.ConfigurationUtilities.ResourceHelper.GetGeneralMessage("NoOTPAvailable");
            }
        }