LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2004, 09:52 AM   #1
ofada
Member
 
Registered: Jan 2004
Posts: 32

Rep: Reputation: 15
MD5 C++ Mysql


Hello
I'm using mysql++ to communicate with a database in C++ and I what to know how to crypt a password in C++ to compare it with the one stored in the mysql database.

Thanks a lot
Bye !!
 
Old 04-13-2004, 10:45 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Off the top of my head, I can think of a couple of options.

1. Use the MD5 function that is part of the OpenSSL crypto library. (man MD5 if you have OpenSSL installed)

2. Use the MD5 function that MySQL has, like so:
SELECT * FROM Users
WHERE Username='someusername' AND
Password=MD5('somepassword')

Last edited by deiussum; 04-13-2004 at 10:50 AM.
 
Old 04-13-2004, 02:28 PM   #3
ofada
Member
 
Registered: Jan 2004
Posts: 32

Original Poster
Rep: Reputation: 15
OK,
Can you tell me a piece of C/C++ code using the functions of crypto library, because i don't understand how does it work.
Thanks
 
Old 04-13-2004, 03:00 PM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Code:
// md5test.c
#include <openssl/md5.h>
#include <stdio.h>

int main()
{
    unsigned char hash[16];
    char* pass = "password";
    int c;

    MD5(pass, strlen(pass), hash);

    printf("0x");
    for (c=0;c<16;c++)
    {
        printf("%.2X", hash[c]);
    }
    printf("\n");
}
Code:
$ gcc -o md5test md5test.c -lcrypto
$ ./md5test
0x5F4DCC3B5AA765D61D8327DEB882CF99
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 17 09-17-2014 02:13 PM
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock welery Linux - Software 19 03-06-2014 07:19 AM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. suziecorbett Linux - Software 8 10-09-2008 01:52 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
using iso.md5 and iso.md5.asc Tyir Linux - Newbie 3 07-10-2004 11:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration