Solved

Decode/encode for .htpasswd (.htaccess) file

Posted on 1997-11-15
2
21,327 Views
Last Modified: 2008-11-28
Hello...

Anyone know how to encode/decode the passwords
in .htpasswd (Apache Webserver) file ?

A piece of code will be greatly appreciated.

Thanks in advance.


Miranda
myr@dnet.net.id
0
Comment
Question by:myr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 200 total points
ID: 1441011
Apache's .htpasswd uses unix's "crypt" function. crypt is a "one way" encryption method used to encrypt passwords. There is an encode ONLY - no decode. In order to check that a password is correct, you have to encode the proposed password and compare the encrypted result with the encrypted password in the .httpd file. If the encrypted strings match, then the passwords match. The whole idea behind this sort of encryption is that you can't find out what the password is, you can only verify whether a proposed password is correct.

The zipfile at http://free.dom.de/xcrypt.html contains a windows DLL which implements the crypt function, as well as sample VB code (the VB code is very simple, "Text2.Text = crypt(Text1.Text)"). There is source for both the VB code and the DLL (DLL source is in C).

The complexity of the crypt algorithm (DES, basically) makes it impractical to implement in VB, though if you really wanted to you could certainly translate the C source to VB code. It would be slow, though.

If all you want to do is to to generate .htpasswd file entries, then you are all set with the zipfile I just mentioned. If you want to actively check passwords in VB, though, then it's not enough because with that DLL you can't specify the "salt". The "salt" is the 3-character string that is used to initialize the encryption. The encrypted password entries in the .htpasswd file include the correct salt as the first 3 characters - so to check a proposed password, you would get the first three characters from the encrypted password you want to check against, and use those as the salt so the encryption would come out the same. If you want to do this, then you can still use the .zipfile I gave you but will need to recompile the dll. The dll uses a fixed salt rather than one passed as an argument, it would be very easy to make the salt a passed argument as well.

I hope this will do the job for you, it's everything you need to know to do this except for decoding passwords (which as I said is impossible, except via dictionary attack). Please leave a comment if I have been unclear about anything... good luck!
0
 

Author Comment

by:myr
ID: 1441012
Thank you very much Alamo!
I've donwloaded the DLL and have a try,
it's work just fine (I'm using VB5).

Miranda
myr@dnet.net.id
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question