public async Task <bool> ValidateUserFromHash(Guid id, string validate) { MongoMember mm = await _memberCollection.Find(Builders <MongoMember> .Filter.Eq(u => u.Id, id)).FirstOrDefaultAsync(); if (mm == null) { return(false); } using (SHA256 sha = SHA256.Create()) { string content = $"{mm.Id}.{mm.PassSalt}.{ConfigurationManager.AppSettings["data:SecretKey"]}"; byte[] hashBytes = sha.ComputeHash(Encoding.UTF8.GetBytes(content)); string expected = Base32Encoding.ToString(hashBytes); bool success = string.Equals(expected, validate, StringComparison.InvariantCultureIgnoreCase); if (success) { ChangeApproval(id, true); } return(success); } }
public async Task <string> GenerateValidationHash(Guid id) { MongoMember mm = await _memberCollection.Find(Builders <MongoMember> .Filter.Eq(u => u.Id, id)).FirstOrDefaultAsync(); if (mm == null) { return(null); } using (SHA256 sha = SHA256.Create()) { string content = $"{mm.Id}.{mm.PassSalt}.{ConfigurationManager.AppSettings["data:SecretKey"]}"; byte[] hashBytes = sha.ComputeHash(Encoding.UTF8.GetBytes(content)); return(Base32Encoding.ToString(hashBytes)); } }