예제 #1
0
        private void ProcessSaslPlainAuth(MxAuth auth)
        {
            string pass = null;
            string user = null;

            byte[] bytes = Convert.FromBase64String(auth.Value);
            string sasl  = Encoding.UTF8.GetString(bytes);

            // trim nullchars
            sasl = sasl.Trim((char)0);
            string[] split = sasl.Split((char)0);

            if (split.Length == 3)
            {
                user = split[1];
                pass = split[2];
            }
            else if (split.Length == 2)
            {
                user = split[0];
                pass = split[1];
            }

            // here you should get the password from youdatabase or auth provider
            const string dbPass = "******";

            // check if username and password is correct
            if (user != null &&
                Regex.IsMatch(user, "user([0-9]|11)$") &&
                pass == dbPass)
            {
                // pass correct
                User = user;
                streamParser.Reset();
                IsAuthenticated = true;
                Send(new Success());
            }
            else
            {
                {
                    // user does not exist or wrong password
                    Send(new Failure(FailureCondition.NotAuthorized));
                }
            }
        }
예제 #2
0
        private void ProcessSaslPlainAuth(MxAuth auth)
        {
            string pass = null;
            string user = null;

            byte[] bytes = Convert.FromBase64String(auth.Value);
            string sasl  = Encoding.UTF8.GetString(bytes);

            // trim nullchars
            sasl = sasl.Trim((char)0);
            string[] split = sasl.Split((char)0);

            if (split.Length == 3)
            {
                user = split[1];
                pass = split[2];
            }
            else if (split.Length == 2)
            {
                user = split[0];
                pass = split[1];
            }

            bool passOk = m_server.Authenticate(pass);

            // check if username and password is correct
            if (user != null && passOk)
            {
                // pass correct
                User = user;
                streamParser.Reset();
                IsAuthenticated = true;
                Send(new Success());
            }
            else
            {
                {
                    // user does not exist or wrong password
                    Send(new Failure(FailureCondition.NotAuthorized));
                }
            }
        }
예제 #3
0
 void ProcessAuth(MxAuth auth)
 {
     string user = null, pass = null;
     Failure failure = null;
     if (auth.SaslMechanism == SaslMechanism.PLAIN)
     {
         byte[] buffer = Convert.FromBase64String(auth.Value);
         string sasl = Encoding.UTF8.GetString(buffer).Trim((char)0);
         string[] split = sasl.Split((char)0);
         if (split.Length == 3)
         {
             user = split[1];
             pass = split[2];
         }
         else if (split.Length == 2)
         {
             user = split[0];
             pass = split[1];
         }
         else
         {
             failure = new Failure(FailureCondition.not_authorized);
         }
     }
     else
     {
         failure = new Failure(FailureCondition.invalid_mechanism);
     }
     if (failure == null)
     {
         user = JIDEscaping.Unescape(user);
         if (!Server.AuthManager.Auth(user, pass, pass.Length == 32))
             failure = new Failure(FailureCondition.not_authorized);
     }
     if (failure == null)
     {
         Session.SetOnline(user);
         Session.Send(new Success());
         Session.Reset();
     }
     else
         Session.Send(failure, DataSentAction.Close);
 }