1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
1 |
/* Copyright (C) 2010 Rackspace
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
15 |
||
16 |
#include "config.h" |
|
17 |
#include "mysql_password.h" |
|
1337.5.3
by Eric Day
Moved sha1 to algorithm directory. |
18 |
#include "drizzled/algorithm/sha1.h" |
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
19 |
#include "drizzled/util/convert.h" |
20 |
||
21 |
using namespace std; |
|
22 |
using namespace drizzled; |
|
23 |
||
24 |
const char* MySQLPasswordName = "mysql_password"; |
|
25 |
||
26 |
MySQLPassword::MySQLPassword(void): |
|
27 |
Item_str_func() |
|
28 |
{ } |
|
29 |
||
30 |
const char *MySQLPassword::func_name() const |
|
31 |
{
|
|
32 |
return MySQLPasswordName; |
|
33 |
}
|
|
34 |
||
35 |
void MySQLPassword::fix_length_and_dec() |
|
36 |
{
|
|
37 |
max_length= args[0]->max_length; |
|
38 |
}
|
|
39 |
||
40 |
bool MySQLPassword::check_argument_count(int n) |
|
41 |
{
|
|
42 |
return (n == 1); |
|
43 |
}
|
|
44 |
||
45 |
String *MySQLPassword::val_str(String *str) |
|
46 |
{
|
|
47 |
String argument; |
|
48 |
String *password= args[0]->val_str(&argument); |
|
49 |
SHA1_CTX ctx; |
|
50 |
uint8_t hash_tmp1[SHA1_DIGEST_LENGTH]; |
|
51 |
uint8_t hash_tmp2[SHA1_DIGEST_LENGTH]; |
|
52 |
||
53 |
SHA1Init(&ctx); |
|
54 |
SHA1Update(&ctx, reinterpret_cast<uint8_t *>(password->ptr()), |
|
55 |
password->length()); |
|
56 |
SHA1Final(hash_tmp1, &ctx); |
|
57 |
||
58 |
SHA1Init(&ctx); |
|
59 |
SHA1Update(&ctx, hash_tmp1, SHA1_DIGEST_LENGTH); |
|
60 |
SHA1Final(hash_tmp2, &ctx); |
|
61 |
||
62 |
str->realloc(SHA1_DIGEST_LENGTH * 2); |
|
63 |
drizzled_string_to_hex(str->ptr(), reinterpret_cast<const char*>(hash_tmp2), |
|
64 |
SHA1_DIGEST_LENGTH); |
|
65 |
str->length(SHA1_DIGEST_LENGTH * 2); |
|
66 |
||
67 |
return str; |
|
68 |
}
|