/// <summary> /// To Change Password /// </summary> /// <param name="data"></param> /// <returns></returns> public bool changepassword(LoginInfoData lidata) { crazyTattoosEntities data = new crazyTattoosEntities(); loginInfo li = new loginInfo(); bool ans = false; //Get loginInfo using old password li = (from l in data.loginInfoes where l.LoginInfoId == lidata.Userid where l.Password == lidata.Oldpassword select l).FirstOrDefault(); if (li != null) { var info = from l in data.loginInfoes where l.LoginInfoId == lidata.Userid select l; foreach (loginInfo li1 in info) { li1.Password = lidata.Password; //set new password for the same } ans = true; } else if (li == null) { ans = false; } data.SaveChanges(); // ans save the changes return(ans); }
//Admin login implementation protected void btnlogin_Click(object sender, EventArgs e) { try { if (chkremeber.Checked) //set Cookies for 90 days { Response.Cookies["UserNamecookie"].Expires = DateTime.Now.AddDays(90); Response.Cookies["passwordcoookie"].Expires = DateTime.Now.AddDays(90); } else {// else - expire the cookies Response.Cookies["UserNamecookie"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["passwordcoookie"].Expires = DateTime.Now.AddDays(-1); } //create cookies Response.Cookies["UserNamecookie"].Value = txtusername.Text.Trim(); Response.Cookies["passwordcoookie"].Value = txtpassword.Text.Trim(); string username, password; username = txtusername.Text.Trim(); password = txtpassword.Text.Trim(); if (Checks.Empty(username) && Checks.Empty(password)) { lblmsg.Text = "*Please fill all fields!!"; } else if (Checks.Empty(username)) { lblmsg.Text = "*Please Enter Username!!"; } else if (Checks.Empty(password)) { lblmsg.Text = "*Please Enter Password!!"; } else if (!Checks.Empty(username) && !Checks.Empty(password)) { LoginInfoData data = new LoginInfoData(); data.Username = username; data.Password = password; loginInfo li = new LoginInfoAction().login(data); // method calling for login if (li != null) { Session["Username"] = txtusername.Text.Trim(); //create session for user Session["UserID"] = li.LoginInfoId; Session["Loginstatus"] = true; Response.Redirect("~/Admin/Dashboard.aspx"); } else { lblmsg.Text = "*Invalid Username Or Password!!"; } } } catch (Exception ex) { lblmsg.Text = ex.Message; } }
/// <summary> /// To perform admin Login /// </summary> public LoginInfo login(LoginInfoData liData) { NZEduEntities data = new NZEduEntities(); LoginInfo li = new LoginInfo(); // linq query li = (from login in data.LoginInfoes where login.UserName == liData.Username & login.Password == liData.Password select login).Single(); return(li); }
//Change admin password implementation protected void lnkaddchnge_Click(object sender, EventArgs e) { try { string oldpassword, newpassword, confirmpassword; oldpassword = txtoldpswd.Text.Trim(); newpassword = txtnewpswd.Text.Trim(); confirmpassword = txtnewpswd.Text.Trim(); if (oldpassword == "" && newpassword == "" && confirmpassword == "") { lblmsg.Text = "*Please Fill all Fields!!"; } else if (oldpassword == "") { lblmsg.Text = "*Please Enter Old Password!!"; } else if (newpassword == "") { lblmsg.Text = "*Please Enter New Password!!"; } else if (confirmpassword == "") { lblmsg.Text = "*Please Enter confirm Password!!"; } else if (newpassword != confirmpassword) { lblmsg.Text = "*Password Doesn't matched!!"; } else if (newpassword == confirmpassword && oldpassword != "" && newpassword != "" && confirmpassword != "") { LoginInfoData data = new LoginInfoData(); if (Session["UserID"] != null) { data.Userid = int.Parse(Session["UserID"].ToString()); data.Password = newpassword; data.Oldpassword = oldpassword; bool result = new LoginInfoAction().changepassword(data); //change password method calling if (result == true) { lblmsg.Text = "*Password Change Successfully!!"; } else { lblmsg.Text = "*Old Password Is Incorrect!!"; } } } } catch (Exception ex) { lblmsg.Text = ex.Message; } }
//Login Admin Panel Implementation public loginInfo login(LoginInfoData liData) { crazyTattoosEntities data = new crazyTattoosEntities(); loginInfo li = new loginInfo(); // linq query li = (from log in data.loginInfoes where log.UserName == liData.Username & log.Password == liData.Password select log).First(); return(li); }
//Change admin password implementation protected void btnSubmit_Click(object sender, EventArgs e) { try { string oldpassword, newpassword, confirmpassword; oldpassword = txtOldPswd.Text.Trim(); newpassword = txtNewPswd.Text.Trim(); confirmpassword = txtConfirmPswd.Text.Trim(); if (Checks.Empty(oldpassword) && Checks.Empty(newpassword) && Checks.Empty(confirmpassword)) { lblmsg.Text = "*Please Fill all Fields!!"; } else if (Checks.Empty(oldpassword)) { lblmsg.Text = "*Old password is required!"; } else if (Checks.Empty(newpassword)) { lblmsg.Text = "*New password is required!"; } else if (Checks.Empty(confirmpassword)) { lblmsg.Text = "*Confirm password is required!"; } else if (newpassword != confirmpassword) { lblmsg.Text = "*Confirm password not matched!"; } else if (newpassword == confirmpassword && !Checks.Empty(oldpassword) && !Checks.Empty(newpassword) && !Checks.Empty(confirmpassword)) { LoginInfoData data = new LoginInfoData(); if (Session["UserID"] != null) { data.Userid = int.Parse(Session["UserID"].ToString()); data.Password = newpassword; data.Oldpassword = oldpassword; if (new LoginInfoAction().changepassword(data)) //change password method calling { lblmsg.Text = "*Password changed successfully!"; } else { lblmsg.Text = "*Old password is incorrect!"; } } } } catch (Exception ex) { lblmsg.Text = ex.Message; } }
//Admin login implementation protected void btnlogin_Click(object sender, EventArgs e) { try { string username, password; username = txtusername.Text.Trim(); password = txtpassword.Text.Trim(); if (username == "") { lblmsg.Text = "Please Enter Username!!"; } else if (password == "") { lblmsg.Text = "Please Enter Password!!"; } else { LoginInfoData data = new LoginInfoData(); //send data to class data.Username = username; data.Password = password; LoginInfo li = new LoginInfoAction().login(data); // method calling for login if (li != null) { Session["Username"] = username; //create session for user Session["UserID"] = li.UserID; Session["Loginstatus"] = true; Response.Redirect("~/Admin/Dashboard.aspx"); } else { lblmsg.Text = "Invalid Username Or Password!!"; } } } catch (Exception ex) { lblmsg.Text = ex.Message; } }
public static NextWindow Init() { try { if (!Directory.Exists(ROOT_DIR)) { Directory.CreateDirectory(ROOT_DIR); } if (!Directory.Exists(PATH_TO_ROOMSFILES)) { Directory.CreateDirectory(PATH_TO_ROOMSFILES); } if (!Directory.Exists(PATH_TO_RECORDS)) { Directory.CreateDirectory(PATH_TO_RECORDS); } } catch { } NextWindow nextWindow = NextWindow.Login; if (File.Exists(AppController.PATH_TO_LOGININFO)) { try { string json = File.ReadAllText(AppController.PATH_TO_LOGININFO); LoginInfoData loginInfo = JsonConvert.DeserializeObject <LoginInfoData>(json); AppController.LoginInfo = loginInfo; nextWindow = NextWindow.Main; } catch { } } return(nextWindow); }
private void OnLoginAccept(LoginInfoData data) { ConnectionManager.Instance.PlayerId = data.Id; ConnectionManager.Instance.LobbyInfoData = data.Data; SceneManager.LoadScene("Lobby"); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string action = context.Request.QueryString["action"]; if (string.Compare(action, "adminLogin", false) == 0) { int varifyCode = 0; if (int.TryParse(context.Request["captcha"], out varifyCode)) { string json = string.Empty; Debug.Write(varifyCode); int sCode = -1; var o = context.Session["varifyCode"]; if (o == null) { json = JsonConvert.SerializeObject(new { IsOk = "NoOk", Msg = "请刷新验证码再试" }); context.Response.Write(json); return; } sCode = int.Parse(o.ToString()); if (sCode == varifyCode) { //验证用户名密码 FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "admin", DateTime.Now, DateTime.Now.AddDays(1), false, "password", "/"); string authticket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, authticket); cookie.Secure = false; cookie.Expires = ticket.Expiration; cookie.Path = FormsAuthentication.FormsCookiePath; context.Response.Cookies.Add(cookie); json = JsonConvert.SerializeObject(new { IsOk = "Ok" }); context.Response.Write(json); } else { json = JsonConvert.SerializeObject(new { IsOk = "NoOk", Msg = "验证码输入有误,请刷新验证码" }); context.Response.Write(json); return; } } else { string json = JsonConvert.SerializeObject(new { IsOk = "NoOk", Msg = "" }); context.Response.Write(json); return; } } else if (string.Compare(action, "yzm", false) == 0) { ValidateCode c = new ValidateCode(); string code = c.CreateValidateCode(4); context.Session["varifyCode"] = code; c.CreateValidateGraphic(code, context); } else if (string.Compare(action, "loginInfo", false) == 0) { context.Response.ContentType = "application/json"; LoginInfoData data = new LoginInfoData(); int page = int.Parse(context.Request["page"]); int limit = int.Parse(context.Request["limit"]); data.code = 0; data.msg = "ok"; data.count = 6; List <LoginInfo> listInfo = new List <LoginInfo>(); listInfo.Add(new LoginInfo() { City = "重庆", Id = 0, Ip = "192.168.1.1", UserName = "******", LoginDate = "2020-6-10 19:00:00", UserOS = "win10" }); listInfo.Add(new LoginInfo() { City = "重庆", Id = 1, Ip = "192.168.1.1", UserName = "******", LoginDate = "2020-6-10 19:00:00", UserOS = "win10" }); listInfo.Add(new LoginInfo() { City = "重庆", Id = 2, Ip = "192.168.1.1", UserName = "******", LoginDate = "2020-6-10 19:00:00", UserOS = "win10" }); listInfo.Add(new LoginInfo() { City = "重庆", Id = 3, Ip = "192.168.1.1", UserName = "******", LoginDate = "2020-6-10 19:00:00", UserOS = "win10" }); listInfo.Add(new LoginInfo() { City = "重庆", Id = 4, Ip = "192.168.1.1", UserName = "******", LoginDate = "2020-6-10 19:00:00", UserOS = "win10" }); listInfo.Add(new LoginInfo() { City = "重庆", Id = 5, Ip = "192.168.1.1", UserName = "******", LoginDate = "2020-6-10 19:00:00", UserOS = "win10" }); data.data = listInfo.Skip((page - 1) * limit).Take(limit).ToList(); context.Response.Write(JsonConvert.SerializeObject(data)); } else if (string.Compare(action, "notice", false) == 0) { context.Response.ContentType = "application/json"; string p = context.Request["page"]; string l = context.Request["limit"]; int page = -1; if (!string.IsNullOrEmpty(p)) { page = int.Parse(p); } int limit = -1; if (!string.IsNullOrEmpty(l)) { limit = int.Parse(l); } NoticeData data = new NoticeData(); data.code = 0; data.msg = "ok"; var list = TestData.getNotice(); if (page < 0 || limit < 0) { data.data = list; } else { data.data = list.Skip((page - 1) * limit).Take(limit).ToList(); } data.count = list.Count(); context.Response.Write(JsonConvert.SerializeObject(data)); } else if (string.Compare(action, "article", false) == 0) { context.Response.ContentType = "application/json"; string p = context.Request["page"]; string l = context.Request["limit"]; int page = -1; if (!string.IsNullOrEmpty(p)) { page = int.Parse(p); } int limit = -1; if (!string.IsNullOrEmpty(l)) { limit = int.Parse(l); } ArticleData data = new ArticleData(); data.code = 0; data.msg = "ok"; var list = TestData.GetArticle(); if (page < 0 || limit < 0) { data.data = list; } else { data.data = list.Skip((page - 1) * limit).Take(limit).ToList(); } data.count = list.Count(); context.Response.Write(JsonConvert.SerializeObject(data)); } else if (string.Compare(action, "uploadImg", false) == 0) { ImgJson iJson = new ImgJson(); iJson.data = new List <string>(); string dir = "\\UpImgs\\" + DateTime.Now.ToString("yyyyMMdd"); string physicsPath = HttpContext.Current.Server.MapPath("~" + dir); if (!System.IO.Directory.Exists(physicsPath)) { System.IO.Directory.CreateDirectory(physicsPath); } for (int i = 0; i < context.Request.Files.Count; i++) { string phPath = string.Empty; //获取上传的文件的对象 HttpPostedFile img = context.Request.Files[i]; //获取上传文件的名称 string s = img.FileName; var strFileExtension = s.Substring(s.LastIndexOf('.') + 1, s.Length - s.LastIndexOf('.') - 1); string allowextension = System.Configuration.ConfigurationManager.AppSettings["ImageType"]; if (allowextension.ToLower().IndexOf(strFileExtension.ToLower()) >= 0) { int len = s.LastIndexOf(".") - s.LastIndexOf("\\") - 1; string fileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString(); string fullName = fileName + "." + strFileExtension; //fileName = fileName.Replace(",", ""); //fullName = fullName.Replace(",", ""); //fullName = fullName.Replace(":", ""); //截取获得上传文件的名称(ie上传会把绝对路径也连带上,这里只得到文件的名称) //string str = System.Guid.NewGuid().ToString("N")+ s.Substring(s.LastIndexOf(".") - 1); // s.Substring(s.LastIndexOf("\\") + 1); string path = dir + "\\" + fullName; phPath = physicsPath + "//" + fullName; //保存文件 img.SaveAs(phPath); iJson.data.Add(path); } } if (iJson.data.Count > 0 && iJson.data.Count == context.Request.Files.Count) { iJson.code = 1; } else { iJson.code = 0; iJson.msg = "上传图片出现错误"; } context.Response.ContentType = "application/json"; context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); context.Response.Write(JsonConvert.SerializeObject(iJson)); } else if (string.Compare(action, "uploadImg1", false) == 0) { context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); string fileType = context.Request["dir"]; string dir = string.Empty; string allowextension = string.Empty; if (fileType == "file") { dir = "\\UpFiles\\" + DateTime.Now.ToString("yyyyMMdd"); allowextension = System.Configuration.ConfigurationManager.AppSettings["FileType"]; } else { dir = "\\UpImgs\\" + DateTime.Now.ToString("yyyyMMdd"); allowextension = System.Configuration.ConfigurationManager.AppSettings["ImageType"]; } try { string physicsPath = HttpContext.Current.Server.MapPath("~" + dir); if (!System.IO.Directory.Exists(physicsPath)) { System.IO.Directory.CreateDirectory(physicsPath); } if (context.Request.Files.Count > 0) { string phPath = string.Empty; //获取上传的文件的对象 HttpPostedFile img = context.Request.Files[0]; //获取上传文件的名称 string s = img.FileName; var strFileExtension = s.Substring(s.LastIndexOf('.') + 1, s.Length - s.LastIndexOf('.') - 1); if (allowextension.ToLower().IndexOf(strFileExtension.ToLower()) >= 0) { int len = s.LastIndexOf(".") - s.LastIndexOf("\\") - 1; string fileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString(); string fullName = fileName + "." + strFileExtension; string path = dir + "\\" + fullName; phPath = physicsPath + "//" + fullName; string pp = path.Replace("\\", "/"); //保存文件 img.SaveAs(phPath); context.Response.Write(JsonConvert.SerializeObject(new { error = 0, url = pp })); } else { context.Response.Write(JsonConvert.SerializeObject(new { error = 1, message = "文件格式不支持" })); } } else { context.Response.Write(JsonConvert.SerializeObject(new { error = 1, message = "网络错误,后台没接收到文件" })); } } catch (Exception) { context.Response.Write(JsonConvert.SerializeObject(new { error = 1, message = "上传图片出错" })); throw; } } else if (string.Compare(action, "noticeAE", false) == 0) { var id = context.Request["noticeId"]; var title = context.Request["noticeTitle"]; var content = context.Request["noticeContent"]; var time = context.Request["DataStart"]; DateTime time1 = DateTime.Now; if (!string.IsNullOrEmpty(time)) { time1 = Convert.ToDateTime(time); } //编辑 if (!string.IsNullOrEmpty(id)) { } else {//新增 } context.Response.Write(JsonConvert.SerializeObject(new { IsOk = "Ok", msg = "操作完成" })); } else if (string.Compare(action, "ArticleAE", false) == 0) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(context.Request.Cookies[FormsAuthentication.FormsCookieName].Value); if (ticket == null) { context.Response.Write(JsonConvert.SerializeObject(new { IsOk = "NoOk", msg = "请刷新页面再试" })); context.Response.End(); } LLArticle article = new LLArticle(); int artId = String.IsNullOrEmpty(context.Request["ArtId"]) ? -1 : int.Parse(context.Request["ArtId"]); string listStr = context.Request["ArtType"]; if ("" != listStr && null != listStr) { article.ArtType = listStr.Split(new char[] { ',' }).Select(str => int.Parse(str)).ToList(); } article.Content = context.Request["Content"]; article.Title = context.Request["ArtTitle"]; article.Digest = context.Request["Digest"]; article.ReadPwd = context.Request["ArtPwd"]; article.Editor = ticket.Name; if (artId > 0) { article.LastUpdatetime = DateTime.Now; } else { article.ArtTime = DateTime.Now; } context.Response.Write(JsonConvert.SerializeObject(new { IsOk = "Ok", msg = "操作成功" })); } else if (string.Compare(action, "articleType", false) == 0) { context.Response.ContentType = "application/json"; string p = context.Request["page"]; string l = context.Request["limit"]; int page = -1; if (!string.IsNullOrEmpty(p)) { page = int.Parse(p); } int limit = -1; if (!string.IsNullOrEmpty(l)) { limit = int.Parse(l); } ArtTypeData data = new ArtTypeData(); data.code = 0; data.msg = "ok"; var list = TestData.GetLLType(); if (page < 0 || limit < 0) { data.data = list; } else { data.data = list.Skip((page - 1) * limit).Take(limit).ToList(); } data.count = list.Count(); context.Response.Write(JsonConvert.SerializeObject(data)); } else if (string.Compare(action, "artTypeAE", false) == 0) { var id = context.Request["TypeId"]; var title = context.Request["TypeTitle"]; var detail = context.Request["TypeDetail"]; var time = context.Request["TypeCTime"]; var isHidden = context.Request["TypeIsHidden"]; DateTime time1 = DateTime.Now; if (!string.IsNullOrEmpty(time)) { time1 = Convert.ToDateTime(time); } //编辑 if (!string.IsNullOrEmpty(id)) { } else {//新增 } context.Response.Write(JsonConvert.SerializeObject(new { IsOk = "Ok", msg = "操作完成" })); } }
public void OnLoginAccept(LoginInfoData data) { GlobalManager.Instance.PlayerId = data.Id; GlobalManager.Instance.LastRecievedLobbyInfoData = data.Data; SceneManager.LoadScene("Lobby"); }