public Card ProduceCard(long cardProfileID, long requestingBranch)
        {
            try
            {
                var card = new Card();

                DateTime currentDate            = DateTime.Now;
                Random   randomizer             = new Random();
                var      cardProfile            = CardProfileDL.RetrieveCardProfileByID(cardProfileID);
                string   CompleteCardProfileBIN = cardProfile.CardBin;
                string   cardType  = cardProfile.CardType;
                var      panlength = 0;

                if (cardType == StatusUtil.CardType.VerveCard.ToString())
                {
                    panlength = 19;
                }
                else if (cardType == StatusUtil.CardType.MasterCard.ToString() || cardType == StatusUtil.CardType.VISA.ToString())
                {
                    panlength = 16;
                }

                int    randomNumberLength = (panlength - 1) - CompleteCardProfileBIN.Length;
                string randNumber         = string.Empty;
                if (randomNumberLength <= 9)
                {
                    randNumber += randomizer.Next(Convert.ToInt32(Math.Pow(10, (double)randomNumberLength))).ToString();
                }
                else
                {
                    randNumber += randomizer.Next(Convert.ToInt32(Math.Pow(10, (double)randomNumberLength - 9))).ToString();
                    randNumber += randomizer.Next(Convert.ToInt32(Math.Pow(10, 9))).ToString();
                }

                //Generate new Card PAN
                string newCardPAN = string.Format("{0}{1}", CompleteCardProfileBIN, randNumber.PadLeft(randomNumberLength, '0'));
                //Get Luhn Digit
                string pan = string.Format("{0}{1}", newCardPAN, GetLuhnAlgorithmNumber(newCardPAN));
                //Get Luhn Digit

                card.CardPan          = Crypter.Encrypt(System.Configuration.ConfigurationManager.AppSettings.Get("ekey"), pan);
                card.HashedCardPan    = PasswordHash.MD5Hash(pan);
                card.CardProfileID    = cardProfile.ID;
                card.RequestingBranch = requestingBranch;
                card.Date             = System.DateTime.Now;
                card.CardExpiryDate   = new DateTime(currentDate.Year, currentDate.Month, 1).AddMonths(Convert.ToInt32(cardProfile.CEDuration));

                return(card);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public static void SendForgotPasswordMail(User user)
        {
            try
            {
                string key = System.Configuration.ConfigurationManager.AppSettings.Get("ekey");
                string encrypted_username = Crypter.Encrypt(key, user.Username);

                string userFullName = user.Lastname + " " + user.Othernames;

                string organization     = System.Configuration.ConfigurationManager.AppSettings.Get("Organization");
                string applicationName  = System.Configuration.ConfigurationManager.AppSettings.Get("ApplicationName");
                string websiteUrl       = System.Configuration.ConfigurationManager.AppSettings.Get("WebsiteUrl");
                string passwordResetUrl = websiteUrl + "User/ResetPassword?rq=" + encrypted_username;;
                string subject          = "Password Reset Request on " + applicationName;

                string fromAddress  = "";
                string smtpUsername = "";
                string smtpPassword = "";
                string smtpHost     = "";
                Int32  smtpPort     = 587;
                bool   smtpUseDefaultCredentials = false;
                bool   smtpEnableSsl             = true;

                MailHelper mailConfig = ConfigurationManager.GetSection("mailHelperSection") as MailHelper;
                if (mailConfig != null && mailConfig.Mail != null)
                {
                    fromAddress  = mailConfig.Mail.FromEmailAddress;
                    smtpUsername = mailConfig.Mail.Username;
                    smtpPassword = mailConfig.Mail.Password;
                }

                if (mailConfig != null && mailConfig.Smtp != null)
                {
                    smtpHost = mailConfig.Smtp.Host;
                    smtpPort = Convert.ToInt32(mailConfig.Smtp.Port);
                    smtpUseDefaultCredentials = Convert.ToBoolean(mailConfig.Smtp.UseDefaultCredentials);
                    smtpEnableSsl             = Convert.ToBoolean(mailConfig.Smtp.EnableSsl);
                }


                string body = "";

                body = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/MailTemplates/ForgotPassword.txt"));
                body = body.Replace("#Organization", organization);
                body = body.Replace("#ApplicationName", applicationName);
                body = body.Replace("#UserFullName", userFullName);
                body = body.Replace("#WebsiteUrl", websiteUrl);
                body = body.Replace("#PasswordResetUrl", passwordResetUrl);

                Thread email = new Thread(delegate()
                {
                    Mail.SendMail(user.Email, fromAddress, subject, body, smtpHost, smtpPort, smtpUseDefaultCredentials, smtpUsername, smtpPassword, smtpEnableSsl);
                });

                email.IsBackground = true;
                email.Start();
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                throw ex;
            }
        }