#23 provide db.setDatabasePassword

Unnassigned
open
nobody
None
2
2013-08-16
2011-02-27
hleofxquotes
No

I see there is a getDatabasePassword() for Database.class. Is it possible to provide a setDatabasePassword().

Thanks,

Discussion

  • James Ahlborn
    James Ahlborn
    2011-02-28

    i tried. apparently, it is more complicated than just changing the password value. some related info must be encoded elsewhere in the db because my attempts to change the password did not seem to be understood by ms access.

     
  • hleofxquotes
    hleofxquotes
    2011-02-28

    Access seems to want "open in exclusive mode" in order to set a password. Don't know if that is a useful clue.

    Do you mind make codes that you have available here anyway.

    Thanks for trying. Appreciated the effort.

     
  • James Ahlborn
    James Ahlborn
    2011-03-02

    i'll see if i can put back together the code i had for modifying the password.

     
  • James Ahlborn
    James Ahlborn
    2011-03-12

    the method below should modify the database password (as far as the data jackcess reads). however, i'm pretty sure access does something with the ACLs based on the password, and that just changing the password value itself won't work.

    public void setDatabasePassword(String newPassword) throws IOException
    {
    _pageChannel.readPage(_buffer, 0);

    ByteBuffer pwdBB = Column.encodeUncompressedText(newPassword,
                                                     getCharset());
    if(pwdBB.remaining() > _format.SIZE_PASSWORD) {
      throw new IllegalArgumentException("Password too long");
    }
    
    byte[] pwdBytes = new byte[_format.SIZE_PASSWORD];
    pwdBB.get(pwdBytes, 0, pwdBB.remaining());
    
    // re-mask password using extra password mask if necessary (the extra
    // password mask is generated from the database creation date stored in
    // the header)
    byte[] pwdMask = getPasswordMask(_buffer, _format);
    if(pwdMask != null) {
      for(int i = 0; i < pwdBytes.length; ++i) {
        pwdBytes[i] ^= pwdMask[i % pwdMask.length];
      }
    }
    
    _buffer.position(_format.OFFSET_PASSWORD);
    _buffer.put(pwdBytes);
    
    _pageChannel.writePage(_buffer, 0);
    

    }

     
  • Thanks. It worked (as far as setting the password "field").

     
  • James Ahlborn
    James Ahlborn
    2011-03-13

    is that useful to you? does ms money check the password differently?

     
  • James Ahlborn
    James Ahlborn
    2013-02-19

    Ticket moved from /p/jackcess/bugs/76/

     
  • James Ahlborn
    James Ahlborn
    2013-08-16

    • Group: --> Unnassigned