//发送验证码 private string SendSecurityCode(string SecurityCode) { phoneNumber = this.user_PhoneNumber.Value.ToString().Trim(); string result = ""; if (MetarnetRegex.IsMobilePhone(phoneNumber)) { ITopClient client = new DefaultTopClient(url, AppKey, Security); AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest(); req.Extend = "123456"; req.SmsType = "normal"; req.SmsFreeSignName = "注册验证"; // req.SmsParam = String.Format("{\"code\":\"1234\",\"product\":\"打堆云打印\"}", SecurityCode);// "{\"code\":\"1234\",\"product\":\"打堆云打印\"}"; req.SmsParam = "{\"code\":\"" + SecurityCode + "\",\"product\":\"打堆云打印\"}"; req.RecNum = phoneNumber; req.SmsTemplateCode = "SMS_3125049"; AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req); result = rsp.Body; } return(result); }
/// <summary> /// 判断输入的字符串是否是合法的IPV6 地址 /// </summary> /// <param name="input"></param> /// <returns></returns> public static bool IsIPV6(string input) { string pattern = ""; string temp = input; string[] strs = temp.Split(':'); if (strs.Length > 8) { return(false); } int count = MetarnetRegex.GetStringCount(input, "::"); if (count > 1) { return(false); } else if (count == 0) { pattern = @"^([\da-f]{1,4}:){7}[\da-f]{1,4}$"; Regex regex = new Regex(pattern); return(regex.IsMatch(input)); } else { pattern = @"^([\da-f]{1,4}:){0,5}::([\da-f]{1,4}:){0,5}[\da-f]{1,4}$"; Regex regex1 = new Regex(pattern); return(regex1.IsMatch(input)); } }
public static MetarnetRegex GetInstance() { if (MetarnetRegex.instance == null) { MetarnetRegex.instance = new MetarnetRegex(); } return(MetarnetRegex.instance); }
//注册时确定按钮 protected void OK_Btu_Click(object sender, EventArgs e) { phoneNumber = this.user_PhoneNumber.Value.ToString().Trim(); if (String.IsNullOrEmpty(phoneNumber)) { MessageTxt.Value = "请输入电话号码!"; return; } if (String.IsNullOrEmpty(this.password.Value.ToString().Trim())) { MessageTxt.Value = "请输入密码!"; return; } else { if (this.password.Value.ToString().Trim() != this.sure_password.Value.ToString().Trim()) { MessageTxt.Value = "两次输入密码不一致!"; return; } } if (MetarnetRegex.IsMobilePhone(phoneNumber)) { if (IsHaveSend && (IdentifyCode.Value.ToString().Trim() == SecurityCode.ToString())) //判断验证码是否正确 { EnUserInfo Euser = new EnUserInfo(); Euser.uerName = this.UserNameText.Value.ToString().Trim(); Euser.phoneNumber = phoneNumber; Euser.registerTime = DateTime.Now; Euser.password = this.password.Value.ToString().Trim(); if (users.Register(Euser)) { MessageTxt.Value = "注册成功!"; //还原 IsHaveSend = false; SecurityCode = 0; return; } } else { MessageTxt.Value = "验证码不正确!"; return; } } else { MessageTxt.Value = "手机号格式不正确!"; return; } }
//忘记密码时确定按钮 protected void OK_Click(object sender, EventArgs e) { phoneNumber = this.UserTel.Value.ToString().Trim(); if (String.IsNullOrEmpty(phoneNumber)) { MessageTxt.Value = "请输入电话号码!"; return; } if (String.IsNullOrEmpty(this.UserNewpassword.Value.ToString().Trim())) { MessageTxt.Value = "请输入密码!"; return; } else { if (this.Sure_Userpassword.Value.ToString().Trim() != this.UserNewpassword.Value.ToString().Trim()) { MessageTxt.Value = "两次输入密码不一致!"; return; } } if (MetarnetRegex.IsMobilePhone(phoneNumber)) { if (IsHaveSend && (IdentCode.Value.ToString().Trim() == SecurityCode.ToString())) //判断验证码是否正确 { string pass = this.UserNewpassword.Value.ToString().Trim(); DataSet ds = DataBase.RunDataSet("select * from UserInfo where PhoneNumber='" + phoneNumber + "'"); DataTable dt = ds.Tables[0]; dt.Rows[0]["Password"] = pass; int k = DataBase.update("UserInfo", "UserRecID", dt); if (k > 0) { MessageTxt.Value = "密码修改成功!"; //还原 IsHaveSend = false; SecurityCode = 0; return; } } else { MessageTxt.Value = "验证码不正确!"; return; } } else { MessageTxt.Value = "手机号格式不正确!"; return; } }
protected void Get_IdentifyCode_Click(object sender, EventArgs e) { phoneNumber = this.UserTelNumber.Text.Trim(); DataSet ds = DataBase.RunDataSet("select * from UserInfo where PhoneNumber='" + phoneNumber + "' and UserName='******'"); if (ds.Tables[0].Rows.Count > 0 && MetarnetRegex.IsMobilePhone(phoneNumber)) { MessageTxt.Value = "请检查你的手机号是否已修改!"; } else { Random rd = new Random(); SecurityCode = rd.Next(1234, 9879); //生成验证码 SendSecurityCode(SecurityCode.ToString()); //发送验证码,后面还要根据返回的值判断是否发送成功 IsHaveSend = true; } }