Ejemplo n.º 1
0
        public static CUser Create(string username, string password)
        {
            byte[] firstKey = Key.GenerateKey();
            byte[] pass     = Hash.ComputeHmachSHA512(Encoding.UTF8.GetBytes(password), firstKey);
            byte[] newSalt  = Salt.GenerateSalt();
            Salt.lastSalt = newSalt;
            byte[] secondKey       = Key.GenerateKey();
            byte[] hashedSalt      = Combine_Hash_Salt.Combine(pass, newSalt);
            string saltHashedHMACH = Convert.ToBase64String(Hash.ComputeSHA512(hashedSalt));

            user = new CUser(username, saltHashedHMACH, Convert.ToBase64String(newSalt), Convert.ToBase64String(firstKey), Convert.ToBase64String(secondKey));

            return(user);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int i = 1;

            while (i == 1)
            {
                Console.WriteLine("Write a username");
                string username = Console.ReadLine();
                Console.WriteLine("Write password");
                string pass = Console.ReadLine();
                CUser  user = CUser.Create(username, pass);
                Conn.InsertIntoDB(user);
                Console.ReadKey();
            }
        }
Ejemplo n.º 3
0
        public static void InsertIntoDB(CUser user)
        {
            if (Connection().State == ConnectionState.Open)
            {
                string Query = "INSERT INTO Login (username, password, salt, key1, key2) VALUES (@username, @password, @salt, @key1, @key2)";

                SqlCommand command = new SqlCommand(Query, Connection());

                command.Parameters.Add("@username", SqlDbType.VarChar).Value = user.Username;
                command.Parameters.Add("@password", SqlDbType.VarChar).Value = user.Password;
                command.Parameters.Add("@salt", SqlDbType.VarChar).Value     = user.SaltVal;
                command.Parameters.Add("@key1", SqlDbType.VarChar).Value     = user.Key1;
                command.Parameters.Add("@key2", SqlDbType.VarChar).Value     = user.Key2;

                command.ExecuteNonQuery();
                Connection().Close();
            }
        }