locked
Connection with msaccess database file without providing password like windows authentication RRS feed

  • Question

  • User-300120154 posted

    I want to make connection with access database file that file having may be password protected.

    So.like sqlserver windows authentication connection,Can I make connection with access database file

     

     

     

    Saturday, April 23, 2011 12:57 AM

Answers

All replies

  • User-821857111 posted
    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;Jet OLEDB:Database Password=MyDbPassword;
    You can't use windows Authentication to password-protect an mdb file as far as I know.
    Saturday, April 23, 2011 2:31 AM
  • User3866881 posted

    Hi:)

    Access doesn't have a real Authentication like SQL Server. In my mind, you can see this article, which may be helpful for you:

    I mean that you can do something authentication like SQL Authentication with MemberShip。

    Something looks like this:

    public override bool ValidateUser(string username, string password)
    {
        using(OleDbConnection conn = new OleDbConnection(m_strDBConnection))
        {
            try
            {
                /* Create command */
                OleDbCommand command =
                         new OleDbCommand("SELECT USERNAME, PASSWORD FROM Users " +
                                          "WHERE USERNAME='" + username +
                                          "' AND PASSWORD='" + password + "'",
                                          conn);

                /* Open connection */
                conn.Open();

                /* Run query */
                OleDbDataReader reader = command.ExecuteReader();

                /* Check if we have something */
                bool bResult = reader.HasRows;

                /* Close connection */
                conn.Close();

                return bResult;
            }
            catch(Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            return false;
        }
    }

    public override bool IsUserInRole(string username, string roleName)
    {
        using (OleDbConnection conn = new OleDbConnection(m_strDBConnection))
        {
            try
            {
                /* Create command */
                OleDbCommand command 
                       = new OleDbCommand("SELECT USERNAME, ROLE_NAME FROM UsersInRoles " +
                                          "WHERE USERNAME='" + username +
                                          "' AND ROLE_NAME='" + roleName + "'",
                                          conn);

                /* Open connection */
                conn.Open();

                /* Run query */
                OleDbDataReader reader = command.ExecuteReader();

                /* Check if there are any rows */
                bool bResult = reader.HasRows;

                /* Close connection */
                conn.Close();

                return bResult;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
        return false;
    }

    public override string[] GetRolesForUser(string username)
    {
        string[] Roles = null;

        using (OleDbConnection conn = new OleDbConnection(m_strDBConnection))
        {
            try
            {
                /* Create command */
                OleDbCommand command =
                          new OleDbCommand("SELECT ROLE_NAME FROM UsersInRoles " +
                                           "WHERE USERNAME='" + username + "'",
                                           conn);

                /* Open connection */
                conn.Open();

                /* Run query */
                OleDbDataReader reader = command.ExecuteReader();

                /* Store all data into String collection */
                StringCollection sc = new StringCollection();
                while (reader.Read())
                    sc.Add(reader.GetString(0));
                Roles = new string[sc.Count];
                sc.CopyTo(Roles, 0);

                /* Close connection */
                conn.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
        return Roles;
    }

    <system.web>
       [...]
       <membership defaultProvider="AccessMembershipProvider">
          <providers>
            <clear/>
            <add name="AccessMembershipProvider"
                 type="AccessProvider.AccessMembershipProvider"
                 connectionStringName="USERSDB"/>
          </providers>
        </membership>
        <roleManager enabled="true" defaultProvider="AccessRoleProvider">
          <providers>
            <clear/>
            <add name="AccessRoleProvider"
                 type="AccessProvider.AccessRoleProvider"
                 connectionStringName="USERSDB"/>
          </providers>
        </roleManager>
       [...]
    </system.web>

    For more please see at:

    http://www.amergerzic.com/post/AccessFormsAuthentication.aspx

    And you can download the free codes at:

    http://www.amergerzic.com/file.axd?file=Authorization.zip

    Monday, April 25, 2011 2:31 AM
  • User1867929564 posted

    I think first u hv to recover or break password.
    http://www.accessforums.net/code-repository/password-extractor-mdw-files-7703.html

    http://repair-password-protected-mdb.qarchive.org/

    http://www.google.co.in/search?hl=en&biw=1004&bih=587&q=recover+password+protected+mdb+&aq=f&aqi=&aql=&oq=

    After you getyour password,tell use which link worked.
    another option is to connect via DAO.
    It won't ask for password while connecting,but will ask before opening.
    refer this,

    http://support.microsoft.com/kb/235422 

    Monday, April 25, 2011 7:24 AM
  • User-1199946673 posted

    Access doesn't have a real Authentication like SQL Server. In my mind, you can see this article, which may be helpful for you:

    Althought I don't think you're answering the questions being asked, when you copy and paste example code, mabye you should check it first? The example code you're shoing is potentially vulnarable to SQL injections but also it will fail. because password is a reserved word in Jet!

    A better, more complete tutorial on using Forms authentication with Access can be found at:

    http://imar.spaanjaars.com/404/using-the-microsoft-access-providers-to-replace-the-built-in-sql-server-providers
    http://imar.spaanjaars.com/560/using-the-microsoft-access-providers-for-membership-roles-and-profile-under-aspnet-4

    Also, when answering, many times you just ciopy and paste code from other websites, and then post the link. Do you know if the author is fine by that? Just posting the link to other resources will be more efficient....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 25, 2011 8:02 AM