protected void Unnamed1_Click(object sender, EventArgs e) { Model.UserInformation cus = new Model.UserInformation(); cus.Name = Name.Text.Trim().ToLower(); cus.Password = pwd.Text.Trim(); cus.loginName = loginname.Text.Trim(); int count = new BLL.UserlnformationBLL().Userinformation(cus); switch (count) { case -3: lblmsg.Text = "您输入的账号已经存在!<br/>请重新选择!"; break; case -2: lblmsg.Text = "数据库连接失败!<br/>请检查您的数据库或联系管理员!"; break; case -1: lblmsg.Text = "数据操作失败!<br/>请检查您输入的数据或联系管理员!"; break; case 0: lblmsg.Text = "注册失败!<br/>请检查您输入的数据!"; break; default: Session["UserInformation"] = cus; lblmsg.Text = "注册成功!你可以<a href='WebSignIn.aspx'>登录了</a>"; break; } }
public string UpdateUserInfo(Model.UserInformation cus) { if (!string.IsNullOrEmpty(cus.Password)) { cus.Password = Encryption(cus.Password); } return(Option(new DAL.UserInformationDAL().UpdateUserInfo(cus), "更新")); }
/// <summary> /// 用户注册 /// </summary> /// <param name="cus"></param> /// <returns></returns> public int Userinformation(Model.UserInformation cus) { if (!new Rule.UserInformation().UserName(cus.Name)) { return(-3); } cus.Password = Encryption(cus.Password); return(new DAL.UserInformationDAL().Userinformation(cus)); }
private void btnDataGenerator_Click(object sender, RoutedEventArgs e) { Model.UserInformation fUser = UserViewModel.GenerateData(); tbLastname.Text = fUser.Lastname; tbFirstname.Text = fUser.Firstname; tbEmail.Text = fUser.email; tbMobile.Text = fUser.mobile; tbUsername.Text = fUser.Username; tbPassword1.Password = tbPassword2.Password = "******"; }
protected void Unnamed1_Click(object sender, EventArgs e) { Model.UserInformation cus = new Model.UserInformation(); //cus.loginName = ((Model.UserInformation)Session["UserInformation"]).loginName; cus.Age = txtage.Text.Trim(); cus.Gender = txtgender.Text.Trim(); cus.Telephone = txtTelephone.Text.Trim(); cus.qq = txtqq.Text.Trim(); cus.Mailbox = txtMailbox.Text.Trim(); cus.UIID = ((Model.UserInformation)Session["UserInformation"]).UIID; lblmsg.Text = new BLL.UserlnformationBLL().UpdateUserInfo(cus); }
protected void Page_Load(object sender, EventArgs e) { Model.UserInformation custe = Session["UserInformation"] as Model.UserInformation; if (custe != null) { if (!IsPostBack) { custe.Age = txtage.Text; custe.Gender = txtgender.Text; custe.Telephone = txtTelephone.Text; custe.qq = txtqq.Text; custe.Mailbox = txtMailbox.Text; } } else { } }
//測試: 產生假的Normal User資料 public static Model.UserInformation GenerateData() { Random r = new Random(); string[] lastNameList = { "趙", "錢", "孫", "李", "陳", "林", "黃", "吳", "張", "簡", "廖", "梁", "蕭", "花", "江", "袁", "蔡", "周", "王", "許", "譚", "鄧", "洪", "何", "郭", "馬", "崔", "馮", "余", "闕", "汪", "方", "莊", "范", "蘇", "詹", "章", "葉", "劉", "毛", "邱", "胡", "溫", "謝", "卓" }; string[] firstNameList = { "小明", "小英", "家偉", "國華", "罔市", "罔腰", "招弟", "阿牛", "小芳", "曉萱", "金寶", "阿狗", "大鼻", "建智", "美美", "小紅", "家豪", "怡君", "小智", "俊雄", "阿良", "兵兵", "冰冰", "曉琪", "丁丁", "美枝", "來福", "惠鈺", "小乖", "小威" }; string fLastname = lastNameList[r.Next(lastNameList.Length)]; string fFastname = firstNameList[r.Next(firstNameList.Length)]; string fMobile = $"09{r.Next(100000000):d8}"; string fUserName = ""; int stringLen = r.Next(3, 8); string alphabetic = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < stringLen; i++) { int charNO = r.Next(52); fUserName += alphabetic[charNO]; } string fEmail = "XXXX@"; for (int i = 0; i < 12; i++) { int charNO = r.Next(52); fEmail += alphabetic[charNO]; } Model.UserInformation fakeUser = new Model.UserInformation { mobile = fMobile, Firstname = fFastname, Lastname = fLastname, Username = fUserName, email = fEmail, }; return(fakeUser); }
public int UpdateUserInfo(Model.UserInformation cus) { string sql = "Update UserInformation set StateID=0"; if (!string.IsNullOrEmpty(cus.Name)) { sql += ",[Name]='" + cus.Name + "'"; } if (!string.IsNullOrEmpty(cus.Password)) { sql += ",[Password]='" + cus.Password + "'"; } if (!string.IsNullOrEmpty(cus.loginName)) { sql += ",[loginName]='" + cus.loginName + "'"; } if (!string.IsNullOrEmpty(cus.Age)) { sql += ",[Age]='" + cus.Age + "'"; } if (!string.IsNullOrEmpty(cus.Gender)) { sql += ",[Gender]='" + cus.Gender + "'"; } if (!string.IsNullOrEmpty(cus.Telephone)) { sql += ",[Telephone]='" + cus.Telephone + "'"; } if (!string.IsNullOrEmpty(cus.qq)) { sql += ",[qq]='" + cus.qq + "'"; } if (!string.IsNullOrEmpty(cus.Mailbox)) { sql += ",[Mailbox]='" + cus.Mailbox + "'"; } sql += " where [UIID]='" + cus.UIID + "'"; return(DbHelp.ExecQuery(sql)); }
public int Userinformation(Model.UserInformation cus) { return(DbHelp.ExecQuery("insert into UserInformation values('" + cus.Name + "','" + cus.Password + "','" + cus.loginName + "','','','','','','','','')")); }
//建立登錄使用者的方法。 public static RegisterErrorTypes CreateUser(string userName, string password, string password2, string email, string firstname, string lastname, string mobile, Image profilePic) { //確認資訊填寫完整程度。 if (userName == "") { return(RegisterErrorTypes.LackOfUsername); } if (email == "") { return(RegisterErrorTypes.LackOfEmail); } if (password == "") { return(RegisterErrorTypes.LackOfPassword); } if (password != password2) { return(RegisterErrorTypes.InconsistentPassword); } Model.WPF_ProjectDBEntities db = new Model.WPF_ProjectDBEntities(); //確認DataEntity中是否已存在相同帳號。 foreach (Model.UserInformation u in db.UserInformations) { if (u.Username == userName) { return(RegisterErrorTypes.DuplicatedUsername); } if (u.email == email) { return(RegisterErrorTypes.DuplicateEmail); } } //用RNGCryptoServiceProvider產生隨機salt,加到cmd的參數中 RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] salt = new byte[32]; rng.GetBytes(salt); //將password加上salt後進行加密 byte[] bytesPassword = Encoding.Unicode.GetBytes(password + Encoding.Unicode.GetString(salt)); SHA256Managed Algorism = new SHA256Managed(); byte[] hashedPassword = Algorism.ComputeHash(bytesPassword); //將Image轉為byte[] MemoryStream ms = new MemoryStream(); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create((BitmapSource)profilePic.Source)); encoder.Save(ms); byte[] imgData = ms.ToArray(); ms.Close(); //經多重檢查無誤後,將帳號資訊登錄於DataEntity中。 Model.UserInformation m = new Model.UserInformation { Username = userName, Password = hashedPassword, email = email, salt = salt, RegistrationDate = DateTime.Now, Firstname = firstname, Lastname = lastname, mobile = mobile, Photo = imgData, UserType = "normal" }; db.UserInformations.Add(m); db.SaveChanges(); return(RegisterErrorTypes.SuccessfulRegistration); }