public String save(String firstName, String lastName, String emailAddress, String password) { if (!System.IO.File.Exists(filePath)) System.IO.File.Create(filePath); loadUsers(); //create the user User user = new User(); user.FirstName = firstName; user.LastName = lastName; user.EmailAddress = emailAddress; user.Password = password; //first verify that this user does not exist if (verifyUserExists(user)) return "User already exists!"; //make sure this temp directory exists or change the location. StreamWriter fileWriter = new StreamWriter(filePath, true); //fileWriter.WriteLine(firstName + " " + lastName + " " + emailAddress + " " + password); fileWriter.WriteLine(user.ToString()); fileWriter.Close(); return "User saved successfully!"; }
/** * * 根据username查询管理员 * */ public User selectUserByUserName(String userName) { String sql = "select * from admin where username='******'"; //Console.WriteLine(sql); connection.Open(); cmd = new MySqlCommand(sql, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); if (dataReader.Read()) { User user = new User(); user.UserName = dataReader["username"].ToString(); user.PassWord = dataReader["password"].ToString(); Console.WriteLine(user.ToString()); //关闭连接 dataReader.Close(); closeConnection(); return user; } //关闭连接 dataReader.Close(); closeConnection(); return null; }
private string GetAnswer(string msg) { AddMessage("Qst: " + msg); string result = "failed"; string[] part = msg.Split(new Char[] { ' ' }); if (part.Length >= 1) { if (part[0].Equals("createuser", StringComparison.CurrentCultureIgnoreCase) && part.Length == 4){ int pwdhash; if(part[1].Length<32 && int.TryParse(part[2], out pwdhash)){ User u = new User { Username = part[1], PasswordHash = pwdhash, Group = GetGroup(part[3]), ID = UserCnt++ }; UserList.Add(u); AddMessage("New User: "******"succ"; } } } AddMessage("Ans: " + result); return result; }