Go Back   FlashFXP Forums > >

Programming Need help with C/C++/Delphi? Ask here and make us all laugh.

Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 10-07-2003, 12:19 AM   #1
dasOp
Member
 
Join Date: Jan 2003
Posts: 91
Question sha1?

darkone, could you please give a short example of how you use the sha1 source to generate the passwords for ioFTPD?
dasOp is offline  
Old 10-07-2003, 12:25 AM   #2
darkone
Disabled
FlashFXP Registered User
ioFTPD Administrator
 
darkone's Avatar
 
Join Date: Dec 2001
Posts: 2,230
Default

VOID HashString(LPSTR szString, PUCHAR pHash)
{
// Hash String
sha1(pHash, (const PUCHAR)szString, strlen(szString));
}

String hash to binary hash: (szData = password as hex, dwData = length of szData)

case DT_PASSWORD:
// Password hash
ZeroMemory(pHexData, sizeof(pHexData));

for (i = 0;i < lpDataRow->dwMaxLength && dwData >= 2;i++)
{
// Copy to work buffer
pHexData[0] = szData[i << 1];
pHexData[1] = szData[(i << 1) + 1];
// Decrease length
dwData -= 2;
// Convert hex to dec
u8 = (UINT8)strtoul(pHexData, &pCheck, 16);
// Sanity check
if (pCheck != &pHexData[2]) break;
// Store to memory
((PUINT8)lpBuffer)[i] = u8;
}
break;

Binary hash to string hash:

case DT_PASSWORD:
// Password hash
Put_Buffer_Format(lpOutBuffer, "%s ", lpDataRow->szName);
for (i = 0;i < lpDataRow->dwMaxLength;i++)
{
// Store to memory
i32 = (INT32)((PUINT8)lpBuffer)[i];
// Convert dec to hex
Put_Buffer_Format(lpOutBuffer, "%02x", i32);
}
Put_Buffer(lpOutBuffer, "\r\n", 2);
break;

I hope you'll catch the idea.. it's pretty simple
darkone is offline  
Old 10-07-2003, 01:38 AM   #3
dasOp
Member
 
Join Date: Jan 2003
Posts: 91
Thumbs up

I did catch the idea. And it is quite simple. It did take me an hour to figure your code out though. Here below is a simple example for the benefit of others:

#include "sha1.h"
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
unsigned char hash[20]; //20 bytes is whats specd
char outbuf[40 + 1]; //result hash is 40 bytes plus NUL
char* pass = "ioFTPD";

sha1(hash, (unsigned char*)pass, strlen(pass));
for (int i = 0; i < 20; ++i)
{
int s = (int)((unsigned char*)hash)[i]; //using int just to avoid loss
sprintf(outbuf + i * 2, "%02x", s); //what we're outputting here is a byte, nothing else
}
outbuf[40] = '\0';
printf("Password hash for user %s is %s\r\n", pass, outbuf);
return 0;
}
dasOp is offline  
Closed Thread

Tags
generate, ioftpd, passwords, sha1, source

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:25 AM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)