示例#1
0
 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);
 }
示例#2
0
        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);
                }
        }
示例#3
0
        public bool ConfirmPassword(string password)
        {
            byte[] passwordHash = HashTools.Hash(password, _passwordSalt);

            return(_passwordHash.SequenceEqual(passwordHash));
        }