/// <summary> /// 用户验证【1-成功;0-失败(账号密码不存在或者不匹配)】 /// </summary> /// <param name="UserName"></param> /// <param name="PassWrod"></param> /// <returns></returns> public int Authentication(string Account, string Pwd) { SqlConnection conn = DBLink.GetConnection(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "AdminAuthentication"; cmd.Parameters.Add(new SqlParameter("@AdminAccount", Account)); cmd.Parameters.Add(new SqlParameter("@AdminPwd", Pwd)); try { conn.Open(); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); if (dt != null) { return(1); } else { return(0); } } catch (Exception) { return(0); } finally { cmd.Dispose(); conn.Close(); } }
/// <summary> /// 用户验证【1-成功;0-失败(账号密码不存在或者不匹配)】 /// </summary> /// <param name="UserName"></param> /// <param name="PassWrod"></param> /// <returns></returns> public int Authentication(string EmployerAccount, string EmployerPwd) { int count = 0; SqlConnection conn = DBLink.GetConnection(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "EmployerAuthentication"; cmd.Parameters.Add(new SqlParameter("@EmployerAccount", EmployerAccount)); cmd.Parameters.Add(new SqlParameter("@EmployerPwd", EmployerPwd)); try { conn.Open(); count = int.Parse(cmd.ExecuteScalar().ToString()); if (count > 0) { return(1); } else { return(0); } } catch (Exception) { return(0); } finally { cmd.Dispose(); conn.Close(); } }
public JsonResult CheckEmailUnique(string email) { var result = false; int count = 0; SqlConnection cnn = DBLink.GetConnection(); //string sqlstr = "Select Count(*) FROM Employer where Email='" + email + "' and IsDelete!=1"; string sqlstr = "Select Count(*) FROM Employer where Email='" + email + "'"; //检查Cookies["Employer"]是否存在(如果用户已经登陆可能是修改信息) if (Request.Cookies["Employer"] != null) { //用户已经登陆 //验证用户名密码是否正确 HttpCookie _cookie = Request.Cookies["Employer"]; string _account = _cookie["EmployerAccount"]; string _password = _cookie["EmployerPwd"];//cookie里存的先自己加密,再url加密的密码 string _isDelete = _cookie["IsDelete"]; //Authentication是自己写的函数,验证账号密码是否正确 if (Employer.Authentication(_account, Server.UrlDecode(_password))) { string url = HttpContext.Request.UrlReferrer.ToString(); int pos = url.LastIndexOf("/") + 1; string actionName = url.Substring(pos, url.Length - pos); //防止登陆用户再注册一个相同邮箱账号 if (actionName.ToLower() == "edit") { Employer employer = GetEmployerDetailsByAccount(_account); //防止修改信息时误判断邮箱已经存在 sqlstr += " and Email!='" + employer.Email + "'"; } } } SqlCommand cmm = new SqlCommand(sqlstr, cnn); cnn.Open(); count = int.Parse(cmm.ExecuteScalar().ToString()); cmm.Dispose(); cnn.Close(); result = (count == 0); return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult CheckLoginAccount(string employeraccount) { var result = false; if (employeraccount.Trim() == "jobsky") { result = false; } else { int count = 0; SqlConnection cnn = DBLink.GetConnection(); //string sqlstr = "Select Count(*) FROM Employer where EmployerAccount='" + employeraccount + "' and IsDelete!=1"; string sqlstr = "Select Count(*) FROM Employer where EmployerAccount='" + employeraccount + "'"; SqlCommand cmm = new SqlCommand(sqlstr, cnn); cnn.Open(); count = int.Parse(cmm.ExecuteScalar().ToString()); cmm.Dispose(); cnn.Close(); result = (count == 0); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public Employer GetEmployerDetailsByAccount(string Account = "") { string account = ""; if (Account == "") { account = EmployerAccount; } else { account = Account; } Employer employer = new Employer(); SqlConnection conn = DBLink.GetConnection(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GetEmployerDetailsByAccount"; cmd.Parameters.Add(new SqlParameter("@EmployerAccount", account)); try { conn.Open(); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); //共27个字段,Emploeyr表所有内容 //ID employer.EmployerID = Int32.Parse(dt.Rows[0]["EmployerID"].ToString()); //账号信息部分 employer.EmployerAccount = dt.Rows[0]["EmployerAccount"].ToString(); employer.EmployerPwd = dt.Rows[0]["EmployerPwd"].ToString(); //联系人信息部分 employer.ContactPersonName = dt.Rows[0]["ContactPersonName"].ToString(); employer.ContactPersonSex = Int16.Parse(dt.Rows[0]["ContactPersonSex"].ToString()); employer.FixedTelephone = dt.Rows[0]["FixedTelephone"].ToString(); employer.MobilePhone = dt.Rows[0]["MobilePhone"].ToString(); employer.Email = dt.Rows[0]["Email"].ToString(); //单位基本信息部分 employer.CompanyName = dt.Rows[0]["CompanyName"].ToString(); employer.ParentCompanyName = dt.Rows[0]["ParentCompanyName"].ToString(); employer.CompanyIntroduction = dt.Rows[0]["CompanyIntroduction"].ToString(); employer.CompanyPhone = dt.Rows[0]["CompanyPhone"].ToString(); employer.OrganizationCode = dt.Rows[0]["OrganizationCode"].ToString(); employer.ValidPeriod = DateTime.Parse(dt.Rows[0]["ValidPeriod"].ToString()); employer.CompanyNature = dt.Rows[0]["CompanyNature"].ToString(); employer.CompanyBusiness = dt.Rows[0]["CompanyBusiness"].ToString(); employer.CompanySize = dt.Rows[0]["CompanySize"].ToString(); employer.RegisteredCapital = decimal.Parse(dt.Rows[0]["RegisteredCapital"].ToString()); employer.IsTop500 = Int32.Parse(dt.Rows[0]["IsTop500"].ToString()); employer.CompanyAreaProvince = dt.Rows[0]["CompanyAreaProvince"].ToString(); employer.CompanyAreaCity = dt.Rows[0]["CompanyAreaCity"].ToString(); employer.CompanyAddress = dt.Rows[0]["CompanyAddress"].ToString(); employer.CityClass = dt.Rows[0]["CityClass"].ToString(); employer.Remark = dt.Rows[0]["Remark"].ToString(); //证件照片 employer.CredentialsDir = dt.Rows[0]["CredentialsDir"].ToString(); //其他字段 employer.RegisterTime = DateTime.Parse(dt.Rows[0]["RegisterTime"].ToString()); employer.IsDelete = Int32.Parse(dt.Rows[0]["IsDelete"].ToString()); return(employer); } catch (Exception) { return(new Employer()); } finally { cmd.Dispose(); conn.Close(); } }