Пример #1
0
        public string CreateUser(string msg, int clientId)
        {
            // Get message as object
            Login login = MessageProccesing.DeserializeObject(msg) as Login;

            // Check if user doesnt already exists in DB
            DbMethods dbConnection = new DbMethods();

            lock (activeUsers[clientId]) { dbConnection = activeUsers[clientId].dbConnection; }
            if (dbConnection.CheckIfNameExist(login.username))
            {
                return(MessageProccesing.CreateMessage(ErrorCodes.USER_ALREADY_EXISTS));
            }

            // Hash password
            login.passwordHash = Security.HashPassword(login.passwordHash);
            if (dbConnection.AddNewUser(login.username, login.passwordHash))
            {
                return(MessageProccesing.CreateMessage(ErrorCodes.NO_ERROR));
            }
            else
            {
                return(MessageProccesing.CreateMessage(ErrorCodes.NO_ERROR));
            }
        }
Пример #2
0
        public string CreateUser(string msg, int clientId)
        {
            string[] fields   = msg.Split("$$", StringSplitOptions.RemoveEmptyEntries);
            string   username = fields[0].Split(':', StringSplitOptions.RemoveEmptyEntries)[1];
            string   password = fields[1].Split(':', StringSplitOptions.RemoveEmptyEntries)[1];
            string   IV       = fields[2].Split(':', StringSplitOptions.RemoveEmptyEntries)[1];
            string   keyHash  = fields[3].Split(':', StringSplitOptions.RemoveEmptyEntries)[1];

            DbMethods dbConnection = new DbMethods();

            lock (activeUsers[clientId]) { dbConnection = activeUsers[clientId].dbConnection; }
            if (dbConnection.CheckIfNameExist(username))
            {
                return(TransmisionProtocol.CreateServerMessage(ErrorCodes.USER_ALREADY_EXISTS, Options.CREATE_USER));
            }

            password = Security.HashPassword(password);
            if (dbConnection.AddNewUser(username, password, IV, keyHash))
            {
                return(TransmisionProtocol.CreateServerMessage(ErrorCodes.NO_ERROR, Options.CREATE_USER));
            }
            else
            {
                return(TransmisionProtocol.CreateServerMessage(ErrorCodes.NO_ERROR, Options.CREATE_USER));
            }
        }