private void createDefaultUserDB() { byte[] salt = HashTools.createRandomSalt(); JArray tusers = new JArray(); JObject seow = new JObject(); seow.Add("name", "Seow"); seow.Add("pass", HashTools.Hash("seow230111", salt)); seow.Add("salt", salt); tusers.Add(seow); salt = HashTools.createRandomSalt(); JObject patrick = new JObject(); patrick.Add("name", "Patrick"); patrick.Add("pass", HashTools.Hash("panda", salt)); patrick.Add("salt", salt); tusers.Add(patrick); salt = HashTools.createRandomSalt(); JObject artem = new JObject(); artem.Add("name", "Artem"); artem.Add("pass", HashTools.Hash("root", salt)); artem.Add("salt", salt); tusers.Add(artem); salt = HashTools.createRandomSalt(); JObject simon = new JObject(); simon.Add("name", "Simon"); simon.Add("pass", HashTools.Hash("pimmel", salt)); simon.Add("salt", salt); tusers.Add(simon); salt = HashTools.createRandomSalt(); JObject guest = new JObject(); guest.Add("name", "Guest"); guest.Add("pass", HashTools.Hash("guess", salt)); guest.Add("salt", salt); tusers.Add(guest); using (StreamWriter file = File.CreateText(Path.Combine(Directory.GetCurrentDirectory(), "userDB.json"))) using (JsonTextWriter writer = new JsonTextWriter(file)) { tusers.WriteTo(writer); } }
internal byte[] createNewSessionKey(string user) { byte[] newSessionKey = HashTools.Hash(new Random(DateTime.Now.Millisecond).Next().ToString() + user, HashTools.createRandomSalt()); if (!sessionKeys.Contains(newSessionKey)) { sessionKeys.Add(newSessionKey); } return(newSessionKey); }