const bcrypt = require("bcrypt");
const express = require("express");
const User = require("./userModel");
const router = express.Router();
// signup route
router.post("/signup", async (req, res) => {
const body = req.body;
if (!(body.email && body.password)) {
return res.status(400).send({ error: "Data not formatted properly" });
}
// creating a new mongoose doc from user data
const user = new User(body);
// generate salt to hash password
const salt = await bcrypt.genSalt(10);
// now we set user password to hashed password
user.password = await bcrypt.hash(user.password, salt);
user.save().then((doc) => res.status(201).send(doc));
});
// login route
router.post("/login", async (req, res) => {
const body = req.body;
const user = await User.findOne({ email: body.email });
if (user) {
// check user password with hashed password stored in the database
const validPassword = await bcrypt.compare(body.password, user.password);
if (validPassword) {
res.status(200).json({ message: "Valid password" });
} else {
res.status(400).json({ error: "Invalid Password" });
}
} else {
res.status(401).json({ error: "User does not exist" });
}
});
module.exports = router;
INSERT INTO `%s_admins` (`user`, `authid`, `immunity`, `srv_flags`, `password`, `gid`, `email`, `extraflags`, `expired`) \
VALUES ('%s', '%s', %d, '%s', SHA(CONCAT('SourceBans', SHA('%s'))), 0, '', 0, %d);",
Хочу в плагине добавить хеширование, чтобы добавить админа в БД через запрос MA.Не понятно что и где ты хэшировать собрался.
Посредством sourcepawn? smlib/crypt.inc at master · bcserv/smlib
Что там в MA хэшируется?
Увидел только
HTML:INSERT INTO `%s_admins` (`user`, `authid`, `immunity`, `srv_flags`, `password`, `gid`, `email`, `extraflags`, `expired`) \ VALUES ('%s', '%s', %d, '%s', SHA(CONCAT('SourceBans', SHA('%s'))), 0, '', 0, %d);",
Если ты пишешь про Web - причем тут GetURandomInt()?
Посмотри как в MA хэшируется тогда.
А можете подробнее? Куда записывается уже захешированное значение?Первая ссылка в Гугле
Тык:const bcrypt = require("bcrypt"); const express = require("express"); const User = require("./userModel"); const router = express.Router(); // signup route router.post("/signup", async (req, res) => { const body = req.body; if (!(body.email && body.password)) { return res.status(400).send({ error: "Data not formatted properly" }); } // creating a new mongoose doc from user data const user = new User(body); // generate salt to hash password const salt = await bcrypt.genSalt(10); // now we set user password to hashed password user.password = await bcrypt.hash(user.password, salt); user.save().then((doc) => res.status(201).send(doc)); }); // login route router.post("/login", async (req, res) => { const body = req.body; const user = await User.findOne({ email: body.email }); if (user) { // check user password with hashed password stored in the database const validPassword = await bcrypt.compare(body.password, user.password); if (validPassword) { res.status(200).json({ message: "Valid password" }); } else { res.status(400).json({ error: "Invalid Password" }); } } else { res.status(401).json({ error: "User does not exist" }); } }); module.exports = router;
Чтобы добавить админа в DB, совсем не нужен MA (только для создания первоначальных таблиц). бери и хэшируй MYSQL-ем.Хочу в плагине добавить хеширование, чтобы добавить админа в БД через запрос MA.
А можете подробнее? Куда записывается уже захешированное значение?
Можете рассказать как?Чтобы добавить админа в DB, совсем не нужен MA. бери и хэшируй MYSQL-ем.
А вообще делай как хочешь. Вышел из чата.
Я тебе пример дал выше в SHA.Можете рассказать как?
random = GetURandomInt();
.......SHA('%s')),random......
\scripting\LK_Module_Admin.sp(238) : error 017: undefined symbol "SHA"Я тебе пример дал выше в SHA.
___C-подобный:random = GetURandomInt(); .......SHA('%s')),random......
То есть ты создаешь рандомный пароль? Или что происходит. Не не не, все, вышел из чата точно, Не отвечай на это сообщение.
\scripting\LK_Module_Admin.sp(238) : error 017: undefined symbol "SHA"
Есть ли такая же библиотека smlib с SHA для 1.10? Пытался ещё скомпилить на 1.9, но в плагине выпадает много ошибок
\scripting\LK_Module_Admin.sp(238) : error 017: undefined symbol "SHA"
Как я понял она не нужна...![]()
smlib/scripting/include/smlib/crypt.inc at aad2c8e963dbd7790096efd7920bd9f3cf76082d · bcserv/smlib
Function Stock Library for Sourcemod with over 350 new functions - bcserv/smlibgithub.com
new random = GetURandomInt();
PrintToChat(iClient, "%i |", random);
FormatEx(szQuery, sizeof(szQuery), "INSERT INTO `%s_admins` (`user`, `authid`, `password`, `gid`, `srv_group`, `srv_password`, `expired`, `email`) VALUES ('%s', '%s', SHA(CONCAT('SourceBans', SHA('%i'))), '%i', '%s', '%i', '1@1.ru')", g_sDBPrefix, szName, szAuth, random, g_Item[index].gid, g_Item[index].srv_group, random, iTime);
g_hDatabase.Query(SQL_Callback_InsertPlayer, szQuery, GetClientUserId(iClient));
А что тебе нужно? Ты хочешь добавить в плагин хеширование, какая разница каким способом ты будешь это делать, через md5 или SHA?Как я понял она не нужна...
Может, вы знаете что не так?
code:new random = GetURandomInt(); PrintToChat(iClient, "%i |", random); FormatEx(szQuery, sizeof(szQuery), "INSERT INTO `%s_admins` (`user`, `authid`, `password`, `gid`, `srv_group`, `srv_password`, `expired`, `email`) VALUES ('%s', '%s', SHA(CONCAT('SourceBans', SHA('%i'))), '%i', '%s', '%i', '1@1.ru')", g_sDBPrefix, szName, szAuth, random, g_Item[index].gid, g_Item[index].srv_group, random, iTime); g_hDatabase.Query(SQL_Callback_InsertPlayer, szQuery, GetClientUserId(iClient));
При исп sha в mysql нормально хеширует, а если плагином-то нет (( Можете глянуть запрос?Вначале плагина подключаешь библиотеку с нужной функцией через #include <названиебиблиотекисэтойфункцией>
и уже в коде где нужно суешь свою функцию для хеша. Либо добавляешь сток в плагин и юзаешь его
Если что, то в запросе sha используется на SQL языке и имеет собственную функцию MySQL :: MySQL 8.0 Reference Manual :: 12.14 Encryption and Compression Functions
new rond = GetURandomInt();
PrintToChat(iClient, "%i", rond);
FormatEx(szQuery, sizeof(szQuery), "INSERT INTO `%s_admins` (`user`, `authid`, `password`, `gid`, `srv_group`, `expired`, `email`) VALUES ('%s', '%s', SHA(CONCAT('SourceBans', SHA('%i'))), '%i', '%s', '%i', '1@1.ru')", g_sDBPrefix, szName, szAuth, rond, g_Item[index].gid, g_Item[index].srv_group, iTime);
Чтобы бралось рандомное число, после чего в ячейку "password" он записывалось в хешированном виде, а в "srv_password" в нормальном. (А-то в предыдущем запросе не было пароля вообще)
#include <smlib>
void b()
{
char crypted[256];
Crypt_MD5(IntToString(int value = GetURandomInt()), crypted, sizeof(crypted));
SQL_FormatQuery(db_handle, sQuery, sizeof(sQuery), "INSERT INTO ... (...`password`, `srv_password`...) VALUES (...'%s', '%i'...)", crypted, value);
db_handle.Query(CB, sQuery, _, DBPrio_High);
}
Не есть хорошо хранить пароли пользователей в открытом видеЧтобы бралось рандомное число, после чего в ячейку "password" он записывалось в хешированном виде, а в "srv_password" в нормальном. (А-то в предыдущем запросе не было пароля вообще)
stock void MD5_String(char[] str, char[] output, int maxlen)
{
int placeholder[64];
Handle md5 = MD5Init();
MD5Update(md5, strlen(str), str, placeholder);
MD5Final(md5, output, maxlen);
delete md5;
}
stock Handle MD5Init()
{
int x[2];
int buf[4];
int input[64];
int update[16];
// MD5Init
x[0] = x[1] = 0;
buf[0] = 0x67452301;
buf[1] = 0xefcdab89;
buf[2] = 0x98badcfe;
buf[3] = 0x10325476;
StringMap map = CreateTrie();
map.SetArray("x", x, 2);
map.SetArray("buf", buf, 4);
map.SetArray("input", input, 64);
map.SetArray("update", update, 16);
return view_as<Handle>(map);
}
stock void MD5Update(Handle maph, int len, char[] str, int[] inputfromfile)
{
StringMap map = view_as<StringMap>(maph);
// MD5Update
int x[2]; map.GetArray("x", x, 2);
int buf[4]; map.GetArray("buf", buf, 4);
int input[64]; map.GetArray("input", input, 64);
int update[16]; map.GetArray("update", update, 16);
int i, ii;
update[14] = x[0];
update[15] = x[1];
int mdi = (x[0] >>> 3) & 0x3F;
if ((x[0] + (len << 3)) < x[0]) {
x[1] += 1;
}
x[0] += len << 3;
x[1] += len >>> 29;
int c = 0;
while (len--) {
if(StrEqual(str, ""))
input[mdi] = inputfromfile[c];
else
input[mdi] = str[c];
mdi += 1;
c += 1;
if (mdi == 0x40) {
for (i = 0, ii = 0; i < 16; ++i, ii += 4)
{
update[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii];
}
// Transform
MD5Transform(buf, update);
mdi = 0;
}
}
map.SetArray("x", x, 2);
map.SetArray("buf", buf, 4);
map.SetArray("input", input, 64);
map.SetArray("update", update, 16);
}
stock void MD5Final(Handle maph, char[] md5, int maxlen)
{
StringMap map = view_as<StringMap>(maph);
// MD5Final
int x[2]; map.GetArray("x", x, 2);
int buf[4]; map.GetArray("buf", buf, 4);
int input[64]; map.GetArray("input", input, 64);
int update[16]; map.GetArray("update", update, 16);
int i, ii;
int padding[64] = {
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int inx[16];
inx[14] = x[0];
inx[15] = x[1];
int mdi = (x[0] >>> 3) & 0x3F;
int len = (mdi < 56) ? (56 - mdi) : (120 - mdi);
update[14] = x[0];
update[15] = x[1];
mdi = (x[0] >>> 3) & 0x3F;
if ((x[0] + (len << 3)) < x[0]) {
x[1] += 1;
}
x[0] += len << 3;
x[1] += len >>> 29;
int c = 0;
while (len--) {
input[mdi] = padding[c];
mdi += 1;
c += 1;
if (mdi == 0x40) {
for (i = 0, ii = 0; i < 16; ++i, ii += 4) {
update[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii];
}
// Transform
MD5Transform(buf, update);
mdi = 0;
}
}
for (i = 0, ii = 0; i < 14; ++i, ii += 4) {
inx[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii];
}
MD5Transform(buf, inx);
int digest[16];
for (i = 0, ii = 0; i < 4; ++i, ii += 4) {
digest[ii] = (buf[i]) & 0xFF;
digest[ii + 1] = (buf[i] >>> 8) & 0xFF;
digest[ii + 2] = (buf[i] >>> 16) & 0xFF;
digest[ii + 3] = (buf[i] >>> 24) & 0xFF;
}
FormatEx(md5, maxlen, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[0], digest[1], digest[2], digest[3], digest[4], digest[5], digest[6], digest[7],
digest[8], digest[9], digest[10], digest[11], digest[12], digest[13], digest[14], digest[15]);
}
static stock void MD5Transform_FF(int &a, int &b, int &c, int &d, int x, int s, int ac)
{
a += (((b) & (c)) | ((~b) & (d))) + x + ac;
a = (((a) << (s)) | ((a) >>> (32-(s))));
a += b;
}
static stock void MD5Transform_GG(int &a, int &b, int &c, int &d, int x, int s, int ac)
{
a += (((b) & (d)) | ((c) & (~d))) + x + ac;
a = (((a) << (s)) | ((a) >>> (32-(s))));
a += b;
}
static stock void MD5Transform_HH(int &a, int &b, int &c, int &d, int x, int s, int ac)
{
a += ((b) ^ (c) ^ (d)) + x + ac;
a = (((a) << (s)) | ((a) >>> (32-(s))));
a += b;
}
static stock void MD5Transform_II(int &a, int &b, int &c, int &d, int x, int s, int ac)
{
a += ((c) ^ ((b) | (~d))) + x + ac;
a = (((a) << (s)) | ((a) >>> (32-(s))));
a += b;
}
static stock void MD5Transform(int[] buf, int[] input){
int a = buf[0];
int b = buf[1];
int c = buf[2];
int d = buf[3];
MD5Transform_FF(a, b, c, d, input[0], 7, 0xd76aa478);
MD5Transform_FF(d, a, b, c, input[1], 12, 0xe8c7b756);
MD5Transform_FF(c, d, a, b, input[2], 17, 0x242070db);
MD5Transform_FF(b, c, d, a, input[3], 22, 0xc1bdceee);
MD5Transform_FF(a, b, c, d, input[4], 7, 0xf57c0faf);
MD5Transform_FF(d, a, b, c, input[5], 12, 0x4787c62a);
MD5Transform_FF(c, d, a, b, input[6], 17, 0xa8304613);
MD5Transform_FF(b, c, d, a, input[7], 22, 0xfd469501);
MD5Transform_FF(a, b, c, d, input[8], 7, 0x698098d8);
MD5Transform_FF(d, a, b, c, input[9], 12, 0x8b44f7af);
MD5Transform_FF(c, d, a, b, input[10], 17, 0xffff5bb1);
MD5Transform_FF(b, c, d, a, input[11], 22, 0x895cd7be);
MD5Transform_FF(a, b, c, d, input[12], 7, 0x6b901122);
MD5Transform_FF(d, a, b, c, input[13], 12, 0xfd987193);
MD5Transform_FF(c, d, a, b, input[14], 17, 0xa679438e);
MD5Transform_FF(b, c, d, a, input[15], 22, 0x49b40821);
MD5Transform_GG(a, b, c, d, input[1], 5, 0xf61e2562);
MD5Transform_GG(d, a, b, c, input[6], 9, 0xc040b340);
MD5Transform_GG(c, d, a, b, input[11], 14, 0x265e5a51);
MD5Transform_GG(b, c, d, a, input[0], 20, 0xe9b6c7aa);
MD5Transform_GG(a, b, c, d, input[5], 5, 0xd62f105d);
MD5Transform_GG(d, a, b, c, input[10], 9, 0x02441453);
MD5Transform_GG(c, d, a, b, input[15], 14, 0xd8a1e681);
MD5Transform_GG(b, c, d, a, input[4], 20, 0xe7d3fbc8);
MD5Transform_GG(a, b, c, d, input[9], 5, 0x21e1cde6);
MD5Transform_GG(d, a, b, c, input[14], 9, 0xc33707d6);
MD5Transform_GG(c, d, a, b, input[3], 14, 0xf4d50d87);
MD5Transform_GG(b, c, d, a, input[8], 20, 0x455a14ed);
MD5Transform_GG(a, b, c, d, input[13], 5, 0xa9e3e905);
MD5Transform_GG(d, a, b, c, input[2], 9, 0xfcefa3f8);
MD5Transform_GG(c, d, a, b, input[7], 14, 0x676f02d9);
MD5Transform_GG(b, c, d, a, input[12], 20, 0x8d2a4c8a);
MD5Transform_HH(a, b, c, d, input[5], 4, 0xfffa3942);
MD5Transform_HH(d, a, b, c, input[8], 11, 0x8771f681);
MD5Transform_HH(c, d, a, b, input[11], 16, 0x6d9d6122);
MD5Transform_HH(b, c, d, a, input[14], 23, 0xfde5380c);
MD5Transform_HH(a, b, c, d, input[1], 4, 0xa4beea44);
MD5Transform_HH(d, a, b, c, input[4], 11, 0x4bdecfa9);
MD5Transform_HH(c, d, a, b, input[7], 16, 0xf6bb4b60);
MD5Transform_HH(b, c, d, a, input[10], 23, 0xbebfbc70);
MD5Transform_HH(a, b, c, d, input[13], 4, 0x289b7ec6);
MD5Transform_HH(d, a, b, c, input[0], 11, 0xeaa127fa);
MD5Transform_HH(c, d, a, b, input[3], 16, 0xd4ef3085);
MD5Transform_HH(b, c, d, a, input[6], 23, 0x04881d05);
MD5Transform_HH(a, b, c, d, input[9], 4, 0xd9d4d039);
MD5Transform_HH(d, a, b, c, input[12], 11, 0xe6db99e5);
MD5Transform_HH(c, d, a, b, input[15], 16, 0x1fa27cf8);
MD5Transform_HH(b, c, d, a, input[2], 23, 0xc4ac5665);
MD5Transform_II(a, b, c, d, input[0], 6, 0xf4292244);
MD5Transform_II(d, a, b, c, input[7], 10, 0x432aff97);
MD5Transform_II(c, d, a, b, input[14], 15, 0xab9423a7);
MD5Transform_II(b, c, d, a, input[5], 21, 0xfc93a039);
MD5Transform_II(a, b, c, d, input[12], 6, 0x655b59c3);
MD5Transform_II(d, a, b, c, input[3], 10, 0x8f0ccc92);
MD5Transform_II(c, d, a, b, input[10], 15, 0xffeff47d);
MD5Transform_II(b, c, d, a, input[1], 21, 0x85845dd1);
MD5Transform_II(a, b, c, d, input[8], 6, 0x6fa87e4f);
MD5Transform_II(d, a, b, c, input[15], 10, 0xfe2ce6e0);
MD5Transform_II(c, d, a, b, input[6], 15, 0xa3014314);
MD5Transform_II(b, c, d, a, input[13], 21, 0x4e0811a1);
MD5Transform_II(a, b, c, d, input[4], 6, 0xf7537e82);
MD5Transform_II(d, a, b, c, input[11], 10, 0xbd3af235);
MD5Transform_II(c, d, a, b, input[2], 15, 0x2ad7d2bb);
MD5Transform_II(b, c, d, a, input[9], 21, 0xeb86d391);
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
iRandom = GetRandomInt(9999999,99999999);
IntToString(iRandom, sBuffer, sizeof(sBuffer));
MD5_String(sBuffer, sCode, sizeof(sCode));
В Materials Admin такое же хеширование?@rgba, Где-то находил тут на форуме хеширование строки в md5, сохранил себе, до сих пор пользуюсь, может пригодится.
Сама функция:stock void MD5_String(char[] str, char[] output, int maxlen) { int placeholder[64]; Handle md5 = MD5Init(); MD5Update(md5, strlen(str), str, placeholder); MD5Final(md5, output, maxlen); delete md5; } stock Handle MD5Init() { int x[2]; int buf[4]; int input[64]; int update[16]; // MD5Init x[0] = x[1] = 0; buf[0] = 0x67452301; buf[1] = 0xefcdab89; buf[2] = 0x98badcfe; buf[3] = 0x10325476; StringMap map = CreateTrie(); map.SetArray("x", x, 2); map.SetArray("buf", buf, 4); map.SetArray("input", input, 64); map.SetArray("update", update, 16); return view_as<Handle>(map); } stock void MD5Update(Handle maph, int len, char[] str, int[] inputfromfile) { StringMap map = view_as<StringMap>(maph); // MD5Update int x[2]; map.GetArray("x", x, 2); int buf[4]; map.GetArray("buf", buf, 4); int input[64]; map.GetArray("input", input, 64); int update[16]; map.GetArray("update", update, 16); int i, ii; update[14] = x[0]; update[15] = x[1]; int mdi = (x[0] >>> 3) & 0x3F; if ((x[0] + (len << 3)) < x[0]) { x[1] += 1; } x[0] += len << 3; x[1] += len >>> 29; int c = 0; while (len--) { if(StrEqual(str, "")) input[mdi] = inputfromfile[c]; else input[mdi] = str[c]; mdi += 1; c += 1; if (mdi == 0x40) { for (i = 0, ii = 0; i < 16; ++i, ii += 4) { update[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii]; } // Transform MD5Transform(buf, update); mdi = 0; } } map.SetArray("x", x, 2); map.SetArray("buf", buf, 4); map.SetArray("input", input, 64); map.SetArray("update", update, 16); } stock void MD5Final(Handle maph, char[] md5, int maxlen) { StringMap map = view_as<StringMap>(maph); // MD5Final int x[2]; map.GetArray("x", x, 2); int buf[4]; map.GetArray("buf", buf, 4); int input[64]; map.GetArray("input", input, 64); int update[16]; map.GetArray("update", update, 16); int i, ii; int padding[64] = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; int inx[16]; inx[14] = x[0]; inx[15] = x[1]; int mdi = (x[0] >>> 3) & 0x3F; int len = (mdi < 56) ? (56 - mdi) : (120 - mdi); update[14] = x[0]; update[15] = x[1]; mdi = (x[0] >>> 3) & 0x3F; if ((x[0] + (len << 3)) < x[0]) { x[1] += 1; } x[0] += len << 3; x[1] += len >>> 29; int c = 0; while (len--) { input[mdi] = padding[c]; mdi += 1; c += 1; if (mdi == 0x40) { for (i = 0, ii = 0; i < 16; ++i, ii += 4) { update[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii]; } // Transform MD5Transform(buf, update); mdi = 0; } } for (i = 0, ii = 0; i < 14; ++i, ii += 4) { inx[i] = (input[ii + 3] << 24) | (input[ii + 2] << 16) | (input[ii + 1] << 8) | input[ii]; } MD5Transform(buf, inx); int digest[16]; for (i = 0, ii = 0; i < 4; ++i, ii += 4) { digest[ii] = (buf[i]) & 0xFF; digest[ii + 1] = (buf[i] >>> 8) & 0xFF; digest[ii + 2] = (buf[i] >>> 16) & 0xFF; digest[ii + 3] = (buf[i] >>> 24) & 0xFF; } FormatEx(md5, maxlen, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", digest[0], digest[1], digest[2], digest[3], digest[4], digest[5], digest[6], digest[7], digest[8], digest[9], digest[10], digest[11], digest[12], digest[13], digest[14], digest[15]); } static stock void MD5Transform_FF(int &a, int &b, int &c, int &d, int x, int s, int ac) { a += (((b) & (c)) | ((~b) & (d))) + x + ac; a = (((a) << (s)) | ((a) >>> (32-(s)))); a += b; } static stock void MD5Transform_GG(int &a, int &b, int &c, int &d, int x, int s, int ac) { a += (((b) & (d)) | ((c) & (~d))) + x + ac; a = (((a) << (s)) | ((a) >>> (32-(s)))); a += b; } static stock void MD5Transform_HH(int &a, int &b, int &c, int &d, int x, int s, int ac) { a += ((b) ^ (c) ^ (d)) + x + ac; a = (((a) << (s)) | ((a) >>> (32-(s)))); a += b; } static stock void MD5Transform_II(int &a, int &b, int &c, int &d, int x, int s, int ac) { a += ((c) ^ ((b) | (~d))) + x + ac; a = (((a) << (s)) | ((a) >>> (32-(s)))); a += b; } static stock void MD5Transform(int[] buf, int[] input){ int a = buf[0]; int b = buf[1]; int c = buf[2]; int d = buf[3]; MD5Transform_FF(a, b, c, d, input[0], 7, 0xd76aa478); MD5Transform_FF(d, a, b, c, input[1], 12, 0xe8c7b756); MD5Transform_FF(c, d, a, b, input[2], 17, 0x242070db); MD5Transform_FF(b, c, d, a, input[3], 22, 0xc1bdceee); MD5Transform_FF(a, b, c, d, input[4], 7, 0xf57c0faf); MD5Transform_FF(d, a, b, c, input[5], 12, 0x4787c62a); MD5Transform_FF(c, d, a, b, input[6], 17, 0xa8304613); MD5Transform_FF(b, c, d, a, input[7], 22, 0xfd469501); MD5Transform_FF(a, b, c, d, input[8], 7, 0x698098d8); MD5Transform_FF(d, a, b, c, input[9], 12, 0x8b44f7af); MD5Transform_FF(c, d, a, b, input[10], 17, 0xffff5bb1); MD5Transform_FF(b, c, d, a, input[11], 22, 0x895cd7be); MD5Transform_FF(a, b, c, d, input[12], 7, 0x6b901122); MD5Transform_FF(d, a, b, c, input[13], 12, 0xfd987193); MD5Transform_FF(c, d, a, b, input[14], 17, 0xa679438e); MD5Transform_FF(b, c, d, a, input[15], 22, 0x49b40821); MD5Transform_GG(a, b, c, d, input[1], 5, 0xf61e2562); MD5Transform_GG(d, a, b, c, input[6], 9, 0xc040b340); MD5Transform_GG(c, d, a, b, input[11], 14, 0x265e5a51); MD5Transform_GG(b, c, d, a, input[0], 20, 0xe9b6c7aa); MD5Transform_GG(a, b, c, d, input[5], 5, 0xd62f105d); MD5Transform_GG(d, a, b, c, input[10], 9, 0x02441453); MD5Transform_GG(c, d, a, b, input[15], 14, 0xd8a1e681); MD5Transform_GG(b, c, d, a, input[4], 20, 0xe7d3fbc8); MD5Transform_GG(a, b, c, d, input[9], 5, 0x21e1cde6); MD5Transform_GG(d, a, b, c, input[14], 9, 0xc33707d6); MD5Transform_GG(c, d, a, b, input[3], 14, 0xf4d50d87); MD5Transform_GG(b, c, d, a, input[8], 20, 0x455a14ed); MD5Transform_GG(a, b, c, d, input[13], 5, 0xa9e3e905); MD5Transform_GG(d, a, b, c, input[2], 9, 0xfcefa3f8); MD5Transform_GG(c, d, a, b, input[7], 14, 0x676f02d9); MD5Transform_GG(b, c, d, a, input[12], 20, 0x8d2a4c8a); MD5Transform_HH(a, b, c, d, input[5], 4, 0xfffa3942); MD5Transform_HH(d, a, b, c, input[8], 11, 0x8771f681); MD5Transform_HH(c, d, a, b, input[11], 16, 0x6d9d6122); MD5Transform_HH(b, c, d, a, input[14], 23, 0xfde5380c); MD5Transform_HH(a, b, c, d, input[1], 4, 0xa4beea44); MD5Transform_HH(d, a, b, c, input[4], 11, 0x4bdecfa9); MD5Transform_HH(c, d, a, b, input[7], 16, 0xf6bb4b60); MD5Transform_HH(b, c, d, a, input[10], 23, 0xbebfbc70); MD5Transform_HH(a, b, c, d, input[13], 4, 0x289b7ec6); MD5Transform_HH(d, a, b, c, input[0], 11, 0xeaa127fa); MD5Transform_HH(c, d, a, b, input[3], 16, 0xd4ef3085); MD5Transform_HH(b, c, d, a, input[6], 23, 0x04881d05); MD5Transform_HH(a, b, c, d, input[9], 4, 0xd9d4d039); MD5Transform_HH(d, a, b, c, input[12], 11, 0xe6db99e5); MD5Transform_HH(c, d, a, b, input[15], 16, 0x1fa27cf8); MD5Transform_HH(b, c, d, a, input[2], 23, 0xc4ac5665); MD5Transform_II(a, b, c, d, input[0], 6, 0xf4292244); MD5Transform_II(d, a, b, c, input[7], 10, 0x432aff97); MD5Transform_II(c, d, a, b, input[14], 15, 0xab9423a7); MD5Transform_II(b, c, d, a, input[5], 21, 0xfc93a039); MD5Transform_II(a, b, c, d, input[12], 6, 0x655b59c3); MD5Transform_II(d, a, b, c, input[3], 10, 0x8f0ccc92); MD5Transform_II(c, d, a, b, input[10], 15, 0xffeff47d); MD5Transform_II(b, c, d, a, input[1], 21, 0x85845dd1); MD5Transform_II(a, b, c, d, input[8], 6, 0x6fa87e4f); MD5Transform_II(d, a, b, c, input[15], 10, 0xfe2ce6e0); MD5Transform_II(c, d, a, b, input[6], 15, 0xa3014314); MD5Transform_II(b, c, d, a, input[13], 21, 0x4e0811a1); MD5Transform_II(a, b, c, d, input[4], 6, 0xf7537e82); MD5Transform_II(d, a, b, c, input[11], 10, 0xbd3af235); MD5Transform_II(c, d, a, b, input[2], 15, 0x2ad7d2bb); MD5Transform_II(b, c, d, a, input[9], 21, 0xeb86d391); buf[0] += a; buf[1] += b; buf[2] += c; buf[3] += d; }
Использование функции (пример):iRandom = GetRandomInt(9999999,99999999); IntToString(iRandom, ssBuffer, sizeof(ssBuffer)); MD5_String(sBuffer, sCode, sizeof(sCode));
Нет, в Material Admin хешируется в SHA:В Materials Admin такое же хеширование?
g_dDatabase.Format(sQuery, sizeof(sQuery), "\
INSERT INTO `%s_admins` (`user`, `authid`, `immunity`, `srv_flags`, `password`, `gid`, `email`, `extraflags`, `expired`) \
VALUES ('%s', '%s', %d, '%s', SHA(CONCAT('SourceBans', SHA('%s'))), 0, '', 0, %d);",
g_sDatabasePrefix, g_sAddAdminInfo[iClient][ADDNAME], g_sAddAdminInfo[iClient][ADDSTEAM], g_iAddAdmin[iClient][ADDIMUN], sFlags,
g_sAddAdminInfo[iClient][ADDPASS], g_iAddAdmin[iClient][ADDTIME]);