Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Development
  3. SetPassword in Trunk Code

SetPassword in Trunk Code

Scheduled Pinned Locked Moved Development
2 Posts 2 Posters 24.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    S
    szll2010
    wrote on last edited by
    #1

    Dear Victor,

    There is a bug in the userdb_objects.cpp in trunk. The setpassword function does not consider the Unicode and MBCS. However, I changed the code to this:
    void User::setPassword(const TCHAR *password, bool clearChangePasswdFlag)
    {
    #ifdef UNICODE
        char *mb = MBStringFromWideString(password);
        CalculateSHA1Hash((BYTE *)mb, strlen(mb), m_passwordHash);
        free(mb);
    #else
        CalculateSHA1Hash((BYTE *)password, _tcslen(password), m_passwordHash);
    #endif
        //CalculateSHA1Hash((BYTE *)password, _tcslen(password), m_passwordHash);
        m_graceLogins = MAX_GRACE_LOGINS;
        m_flags |= UF_MODIFIED;
        if (clearChangePasswdFlag)
            m_flags &= ~UF_CHANGE_PASSWORD;
    }
    Still has the problem with setting or changing the password.

    Could you check?

    best regards,

    szll2010

    1 Reply Last reply
    0
    • V
      V
      Victor Kirhenshtein
      wrote on last edited by
      #2

      Hi!

      I changed both setPassword and validatePassword to use UTF-8 instead of current server's page to calculate hash:

      bool User::validatePassword(const TCHAR *password)
      {
        BYTE hash[SHA1_DIGEST_SIZE];

      #ifdef UNICODE
          char mbPassword[1024];
          WideCharToMultiByte(CP_UTF8, 0, password, -1, mbPassword, 1024, NULL, NULL);
          mbPassword[1023] = 0;
          CalculateSHA1Hash((BYTE *)mbPassword, strlen(mbPassword), hash);
      #else
          CalculateSHA1Hash((BYTE *)password, strlen(password), hash);
      #endif
          return !memcmp(hash, m_passwordHash, SHA1_DIGEST_SIZE);
      }

      void User::setPassword(const TCHAR *password, bool clearChangePasswdFlag)
      {
      #ifdef UNICODE
          char mbPassword[1024];
          WideCharToMultiByte(CP_UTF8, 0, password, -1, mbPassword, 1024, NULL, NULL);
          mbPassword[1023] = 0;
          CalculateSHA1Hash((BYTE *)mbPassword, strlen(mbPassword), m_passwordHash);
      #else
          CalculateSHA1Hash((BYTE *)password, strlen(password), m_passwordHash);
      #endif
          m_graceLogins = MAX_GRACE_LOGINS;
          m_flags |= UF_MODIFIED;
          if (clearChangePasswdFlag)
              m_flags &= ~UF_CHANGE_PASSWORD;
      }

      tested it on Russian, Chinese, and Japanese characters - works fine. This solution, however, will cause problem for already set non-latin1 passwords - they will need to be reset.

      Changed code already commited to svn.

      Best regards,
      Victor

      1 Reply Last reply
      0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      Powered by NodeBB Contributors
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups