/// <summary>
        /// GetCodeWithExternalSystem method implmentation
        /// </summary>
        public NotificationStatus GetCodeWithExternalSystem(Registration reg, ExternalOTPProvider externalsys, CultureInfo culture, out int otp)
        {
            SMS_strings.Culture = culture;
            SMSRuntime.Initialize(externalsys);
            SMSParams Params = new SMSParams();

            try
            {
                int zotp = GetRandomOTP();

                Params.IPhost      = SMSRuntime.IPhost;
                Params.Password    = SMSRuntime.Password;
                Params.SMSText     = string.Format(SMS_strings.SMSMessage, externalsys.Company, zotp);
                Params.PhoneNumber = reg.PhoneNumber;

                int errorId;

                if (SMSRuntime.Authenticate(Params, out errorId, externalsys.Timeout))
                {
                    otp = zotp;
                    return(NotificationStatus.ResponseSMSOTP);
                }
                else
                {
                    otp = 0;
                    return(NotificationStatus.Error);
                }
            }
            catch (Exception ex)
            {
                Log.WriteEntry("SMS SendMessage : \r" + ex.Message, EventLogEntryType.Error, 10000);
                otp = 0;
                return(NotificationStatus.Error);
            }
        }
        /// <summary>
        /// GetUserCodeWithExternalSystem method implementation for Azure MFA
        /// </summary>
        public int GetUserCodeWithExternalSystem(string upn, string phonenumber, string smstext, ExternalOTPProvider externalsys, CultureInfo culture)
        {
            SMS_strings.Culture = culture;
            SMSRuntime.Initialize(externalsys);
            SMSParams Params = new SMSParams();

            try
            {
                int otp = GetRandomOTP();

                Params.IPhost      = SMSRuntime.IPhost;
                Params.Password    = SMSRuntime.Password;
                Params.SMSText     = string.Format(SMS_strings.SMSMessage, externalsys.Company, otp);
                Params.PhoneNumber = phonenumber;

                int errorId;

                if (SMSRuntime.Authenticate(Params, out errorId, externalsys.Timeout))
                {
                    return(Convert.ToInt32(otp));
                }
                else
                {
                    return((int)NotificationStatus.Error);
                }
            }
            catch (Exception ex)
            {
                Log.WriteEntry("SMS SendMessage : \r" + ex.Message, EventLogEntryType.Error, 10000);
                return((int)NotificationStatus.Error);
            }
        }
예제 #3
0
        /// <summary>
        /// SendMessage method implmentation
        /// </summary>
        private static bool SendMessage(SMSParams smsParams, out string smsid, out int error_id)
        {
            smsid    = "";
            error_id = 0;

            try
            {
                string         url     = CreateMessage(smsParams);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                HttpWebResponse response = null;
                try
                {
                    response = (HttpWebResponse)request.GetResponse();
                    Stream      dataStream = response.GetResponseStream();
                    XmlDocument doc        = new XmlDocument();
                    doc.Load(dataStream);
                    XmlNode root = doc.SelectSingleNode("/response");
                    error_id = Convert.ToInt32(root["error_code"].InnerText);
                    smsid    = root["smsid"].InnerText;
                }
                finally
                {
                    response.Close();
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.WriteEntry("SMS SendMessage : \r" + ex.Message, EventLogEntryType.Error, 10001);
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        /// InternalAuthenticate method implementation
        /// </summary>
        private static bool InternalAuthenticate(SMSParams smsParams, out int error_id, int timeout = 300)
        {
            error_id = 0;

            string smsid;

            if (SendMessage(smsParams, out smsid, out error_id))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
 /// <summary>
 /// Authenticate method implmentation
 /// </summary>
 public static bool Authenticate(SMSParams smsParams, out int errorId, int timeout = 300)
 {
     return(InternalAuthenticate(smsParams, out errorId, timeout));
 }
예제 #6
0
 /// <summary>
 /// CreateMessage method implmentation
 /// </summary>
 private static string CreateMessage(SMSParams smsParams)
 {
     return(string.Format(_target, smsParams.IPhost, smsParams.Password, smsParams.PhoneNumber, smsParams.SMSText));
 }