i have a sha256 encryption for passwords on my game and i found that i cant make a password recovery option on my games site that uses email and account name cause it just sends the encrypted 65 digit password to the lost accounts email
this is the encryption process i used to secure my passwords into my database
is there a way around decrypting all the passwords and just using a decryption when u submit a password recovery ticket for the single account
#ifndef SHA256_FAST
for (i = 0; i < HASH_SIZE; ++i)
{
s[i] = ctx->h[i];
}
#else // SHA256_FAST
a = ctx->h[0]; b = ctx->h[1];
c = ctx->h[2]; d = ctx->h[3];
e = ctx->h[4]; f = ctx->h[5];
g = ctx->h[6]; h = ctx->h[7];
#endif // SHA256_FAST
#ifndef SHA256_FAST
for (i = 0; i < 16; ++i)
{
PACK_U32(w[i], data + (i << 2))
}
#else // SHA256_FAST
R1(0) R1(1) R1(2) R1(3) R1(4) R1(5) R1(6) R1(7)
R1(8) R1(9) R1(10) R1(11) R1(12) R1(13) R1(14) R1(15)
#endif // SHA256_FAST
#ifndef SHA256_FAST
for (i = 0; i < 64; ++i)
{
t = s[7] + (RR(s[4], 6) ^ RR(s[4], 11) ^ RR(s[4], 25)) + (s[6] ^ (s[4] & (s[5] ^ s[6]))) + \
k[i] + (i < 16 ? w[i] : (F1(i)));
s[7] = s[6]; s[6] = s[5]; s[5] = s[4];
s[4] = s[3] + t;
s[3] = s[2]; s[2] = s[1]; s[1] = s[0];
s[0] = t + (RR(s[1], 2) ^ RR(s[1], 13) ^ RR(s[1], 22)) + ((s[1] & s[2]) | (s[3] & (s[1] | s[2])));
}
#else // SHA256_FAST
R2(a, b, c, d, e, f, g, h, 0) R2(h, a, b, c, d, e, f, g, 1)
R2(g, h, a, b, c, d, e, f, 2) R2(f, g, h, a, b, c, d, e, 3)
R2(e, f, g, h, a, b, c, d, 4) R2(d, e, f, g, h, a, b, c, 5)
R2(c, d, e, f, g, h, a, b, 6) R2(b, c, d, e, f, g, h, a, 7)
R2(a, b, c, d, e, f, g, h, 8) R2(h, a, b, c, d, e, f, g, 9)
R2(g, h, a, b, c, d, e, f, 10) R2(f, g, h, a, b, c, d, e, 11)
R2(e, f, g, h, a, b, c, d, 12) R2(d, e, f, g, h, a, b, c, 13)
R2(c, d, e, f, g, h, a, b, 14) R2(b, c, d, e, f, g, h, a, 15)
R2(a, b, c, d, e, f, g, h, 16) R2(h, a, b, c, d, e, f, g, 17)
R2(g, h, a, b, c, d, e, f, 18) R2(f, g, h, a, b, c, d, e, 19)
R2(e, f, g, h, a, b, c, d, 20) R2(d, e, f, g, h, a, b, c, 21)
R2(c, d, e, f, g, h, a, b, 22) R2(b, c, d, e, f, g, h, a, 23)
R2(a, b, c, d, e, f, g, h, 24) R2(h, a, b, c, d, e, f, g, 25)
R2(g, h, a, b, c, d, e, f, 26) R2(f, g, h, a, b, c, d, e, 27)
R2(e, f, g, h, a, b, c, d, 28) R2(d, e, f, g, h, a, b, c, 29)
R2(c, d, e, f, g, h, a, b, 30) R2(b, c, d, e, f, g, h, a, 31)
R2(a, b, c, d, e, f, g, h, 32) R2(h, a, b, c, d, e, f, g, 33)
R2(g, h, a, b, c, d, e, f, 34) R2(f, g, h, a, b, c, d, e, 35)
R2(e, f, g, h, a, b, c, d, 36) R2(d, e, f, g, h, a, b, c, 37)
R2(c, d, e, f, g, h, a, b, 38) R2(b, c, d, e, f, g, h, a, 39)
R2(a, b, c, d, e, f, g, h, 40) R2(h, a, b, c, d, e, f, g, 41)
R2(g, h, a, b, c, d, e, f, 42) R2(f, g, h, a, b, c, d, e, 43)
R2(e, f, g, h, a, b, c, d, 44) R2(d, e, f, g, h, a, b, c, 45)
R2(c, d, e, f, g, h, a, b, 46) R2(b, c, d, e, f, g, h, a, 47)
R2(a, b, c, d, e, f, g, h, 48) R2(h, a, b, c, d, e, f, g, 49)
R2(g, h, a, b, c, d, e, f, 50) R2(f, g, h, a, b, c, d, e, 51)
R2(e, f, g, h, a, b, c, d, 52) R2(d, e, f, g, h, a, b, c, 53)
R2(c, d, e, f, g, h, a, b, 54) R2(b, c, d, e, f, g, h, a, 55)
R2(a, b, c, d, e, f, g, h, 56) R2(h, a, b, c, d, e, f, g, 57)
R2(g, h, a, b, c, d, e, f, 58) R2(f, g, h, a, b, c, d, e, 59)
R2(e, f, g, h, a, b, c, d, 60) R2(d, e, f, g, h, a, b, c, 61)
R2(c, d, e, f, g, h, a, b, 62) R2(b, c, d, e, f, g, h, a, 63)
#endif // SHA256_FAST
sha256 is in the class of "one-way hash functions". The very definition of a one-way hash is a hash that cannot be "undone". You have to pick a two-way hash function.
I would avoid the trouble of storing the password using reversible encryption. Why trouble? Well, to be honest, I don't know. But nowadays people sue everyone over everything. The best recovery method you can develop is:
1. Email the user a link to reset the password to the registered email.
2. If the user clicks on the link sent (which expires after certain time period) you allow the user to set a new password instead of trying to recover the original one.
3. If the link is not used, you take absolutely no action.
Oh and PLEASE be sure that the email addresses registered under your site/application are truly the accounts of your players. I hate receiving mail from websites that don't validate email addresses.