Encrypt Password in Login Form with ASP.NET MVC and Entity Framework

Encrypt Password in Login Form with ASP.NET MVC and Entity Framework

Learning Programming

8 лет назад

32,545 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Sebastián Acosta Montero
Sebastián Acosta Montero - 08.05.2023 23:38

HeLPER?

Ответить
Yogesh Gund
Yogesh Gund - 09.11.2022 13:52

Getting an exeption on de.SaveChanges();
Exception='Unable to update the EntitySet 'Account' because it has a DefiningQuery and no <InsertFunction> element exists in the
ModificationFunctionMapping> element to support the current operation.'

Ответить
Riz Fer
Riz Fer - 15.01.2020 03:33

can you help me, i can't find verifyHash in passwordhelper

Ответить
Punith R Badiger
Punith R Badiger - 25.12.2018 09:57

public class PasswordHelper
{
public static string ComputeHash(string plainText,
string hashAlgorithm,
byte[] saltBytes)
{
// If salt is not specified, generate it on the fly.
if (saltBytes == null)
{
// Define min and max salt sizes.
int minSaltSize = 4;
int maxSaltSize = 8;

// Generate a random number for the size of the salt.
Random random = new Random();
int saltSize = random.Next(minSaltSize, maxSaltSize);

// Allocate a byte array, which will hold the salt.
saltBytes = new byte[saltSize];

// Initialize a random number generator.
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

// Fill the salt with cryptographically strong byte values.
rng.GetNonZeroBytes(saltBytes);
}

// Convert plain text into a byte array.
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

// Allocate array, which will hold plain text and salt.
byte[] plainTextWithSaltBytes =
new byte[plainTextBytes.Length + saltBytes.Length];

// Copy plain text bytes into resulting array.
for (int i = 0; i < plainTextBytes.Length; i++)
plainTextWithSaltBytes[i] = plainTextBytes[i];

// Append salt bytes to the resulting array.
for (int i = 0; i < saltBytes.Length; i++)
plainTextWithSaltBytes[plainTextBytes.Length + i] = saltBytes[i];

// Because we support multiple hashing algorithms, we must define
// hash object as a common (abstract) base class. We will specify the
// actual hashing algorithm class later during object creation.
HashAlgorithm hash;

// Make sure hashing algorithm name is specified.
if (hashAlgorithm == null)
hashAlgorithm = "";

// Initialize appropriate hashing algorithm class.
switch (hashAlgorithm.ToUpper())
{
case "SHA1":
hash = new SHA1Managed();
break;

case "SHA256":
hash = new SHA256Managed();
break;

case "SHA384":
hash = new SHA384Managed();
break;

case "SHA512":
hash = new SHA512Managed();
break;

default:
hash = new MD5CryptoServiceProvider();
break;
}

// Compute hash value of our plain text with appended salt.
byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);

// Create array which will hold hash and original salt bytes.
byte[] hashWithSaltBytes = new byte[hashBytes.Length +
saltBytes.Length];

// Copy hash bytes into resulting array.
for (int i = 0; i < hashBytes.Length; i++)
hashWithSaltBytes[i] = hashBytes[i];

// Append salt bytes to the result.
for (int i = 0; i < saltBytes.Length; i++)
hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];

// Convert result into a base64-encoded string.
string hashValue = Convert.ToBase64String(hashWithSaltBytes);

// Return the result.
return hashValue;
}

}

Ответить
Subhi Shukla
Subhi Shukla - 05.10.2018 10:16

PasswordHelper.cs ... Can u give Code ?

Ответить
Louieje Guisehan
Louieje Guisehan - 05.06.2018 06:04

so it's not for free?

Ответить
Dzunisani Mushwana
Dzunisani Mushwana - 08.03.2018 12:08

PasswordHelper.cs can i get the class?

Ответить
Sindhuja K S
Sindhuja K S - 24.01.2018 10:37

in this example how can i implement forgot password feature . can you please tell me

Ответить
Agung wicaksono
Agung wicaksono - 14.01.2017 06:55

why can't I login ?
my error inLogin method  :
Line 62:             Account account2 = db.Accounts.Find(accountViewModel.Account.Username);

and in my browser:
The argument types 'Edm.Int64' and 'Edm.String' are incompatible for this operation. Near WHERE predicate, line 1, column 70.

Ответить
jmetjm
jmetjm - 28.11.2016 17:45

hi, how to do validation if i have insert password in HASHBYTES SHA1 in the database?

Ответить
Trushar Tandel
Trushar Tandel - 15.09.2016 00:32

Learning programming must say, you don't need English to grow... you are awesome.. you are clear on what you are explaining. you are true rock-star.

Ответить
Emircan Aziz Hazır
Emircan Aziz Hazır - 22.07.2016 07:44

if you show something for us u MUST to show all of CLEAR..Where is the hash.cs ?? sorry bro .. to much ego kill your talents! No one dont need buy your book.

Ответить
Drank4
Drank4 - 19.06.2016 20:33

at first I though there was something wrong with my sound xD very useful information, too quiet in my opinion but the message at least was clear

Ответить
John Sailor
John Sailor - 02.05.2016 06:36

why razor????

Ответить
nataliaps
nataliaps - 13.03.2016 23:25

why did you create a viewmodel for the Account model if they're the same?

Ответить
azamali khan
azamali khan - 28.12.2015 12:05

"My Demo" what is that?

Ответить