コード例 #1
0
ファイル: Server.cs プロジェクト: jterweeme/spchat
        private void ListenForIncomingConnections()
        {
            while (true)
            {
                var clientSocket = _serverSocket.AcceptTcpClient();
                BetterConsole.WriteLog($"New client connected.");
                var unauthenticatedClient = new Client(clientSocket);

                Clients.Add(unauthenticatedClient);
            }
        }
コード例 #2
0
        public static bool Authenticate(Client client, string username, string password)
        {
            var encodedPassword = new UTF8Encoding().GetBytes(password);
            var hashedPassword = MD5.Create().ComputeHash(encodedPassword);

            var matchedUser = Database.GetDatabase()
                .UserAccounts.FirstOrDefault(u => u.Username.Equals(username) && u.HashedPassword.SequenceEqual(hashedPassword));
            
            if (matchedUser == null)
                return false;

            client.User = matchedUser;
            client.Authenticated = true;

            return true;
        }
コード例 #3
0
        public static bool Register(Client client, string username, string password)
        {
            var database = Database.GetDatabase();

            var encodedPassword = new UTF8Encoding().GetBytes(password);
            var hashedPassword = MD5.Create().ComputeHash(encodedPassword);

            if (database.UserAccounts.Any(u => u.Username == username))
            {
                return false;
            }

            var newUser = new UserAccount
            {
                Username = username,
                HashedPassword = hashedPassword
            };

            database.UserAccounts.Add(newUser);
            database.SaveDatabases();

            return true;
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: jterweeme/spchat
 public void RemoveClient(Client client)
 {
     Clients.Remove(client);
 }