-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
298 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Text; | ||
using System; | ||
|
||
public static class StringHasher | ||
{ | ||
public static uint StringId(string str) | ||
{ | ||
// Uses FNV-1a 32 as the base hash function | ||
const uint prime = 0x1000193; | ||
uint hash = 0x811C9DC5; | ||
|
||
// Convert the string to bytes in UTF-16 (each char is 2 bytes) | ||
byte[] data = Encoding.Unicode.GetBytes(str); | ||
int len = data.Length; | ||
|
||
for (int i = 0; i < len; i += 4) | ||
{ | ||
uint value = 0; | ||
int end = Math.Min(i + 4, len); | ||
|
||
for (int j = i; j < end; ++j) | ||
{ | ||
uint chr = data[j]; | ||
value |= chr << ((j - i) * 8); | ||
} | ||
|
||
hash = (hash ^ value) * prime; | ||
} | ||
|
||
return hash; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
AlcatrazDbContext/Migrations/20241031073735_UpdatePasswordStorage.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
AlcatrazDbContext/Migrations/20241031073735_UpdatePasswordStorage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Alcatraz.DTO.Helpers; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using System; | ||
|
||
|
||
#nullable disable | ||
|
||
namespace Alcatraz.Context.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class UpdatePasswordStorage : Migration | ||
{ | ||
MainDbContext _dbContext; | ||
public UpdatePasswordStorage(MainDbContext context) | ||
{ | ||
_dbContext = context; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
foreach (var user in _dbContext.Users) | ||
{ | ||
user.Password = SecurePasswordHasher.Hash($"{user.Id}-{user.Password}"); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.