Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LoginRadius/csharp-password-hash
.NET standard library to secure the passwords using multiple hashing algorithms.
https://github.com/LoginRadius/csharp-password-hash
Last synced: about 2 months ago
JSON representation
.NET standard library to secure the passwords using multiple hashing algorithms.
- Host: GitHub
- URL: https://github.com/LoginRadius/csharp-password-hash
- Owner: LoginRadius
- License: mit
- Created: 2020-09-21T13:56:37.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-26T09:19:31.000Z (8 months ago)
- Last Synced: 2024-04-17T07:05:36.884Z (7 months ago)
- Language: C#
- Size: 51.8 KB
- Stars: 7
- Watchers: 9
- Forks: 13
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# csharp-password-hash
.NET standard library to secure the passwords using multiple hashing algorithms.## Features
* Secure the passwords using different types of hashing algos
* Uses of the different Encoding types
* Generating random salt
* Unit test cases to check the library fuctionality## Getting Started
* Must have the latest version of the Visual StudioClone `csharp-password-hash` into your system using below commands:
Open command prompt and type below commands
```
git clone https://github.com/LoginRadius/csharp-password-hash
cd csharp-password-hash
csharp-password-hash.sln
```
It will open the solution into the Visual Studio
## Usage
Below are samples to show how you might use the library.### Create user model class
```C#
public class User{
public string EmailId{get;set;}
public string Password{get;set;}
}
```
### Create user object
```C#
//Create user object and set emailId and password properties
var userObject = new User
{
EmailId = "[email protected]",
Password = "Test#11"
};
```
### Example 1 - Create HashConfig object (When GeneratePerPasswordSalt is true)
```C#
//Create HashConfig object and set below properties
var hashConfig = new HashingConfig
{
GeneratePerPasswordSalt = true, // This property is used when we have generate different password salt
GlobalSalt = null, // This is used when we have to use the same salt for every password
SaltedPasswordFormat = "#PasswordPlaceHolder#--#SaltPlaceHolder#",// Format which will be used in salted password
HashingAlgo = HashingAlgo.MD5, // Hashing algo which we want to use
PasswordHashEncodingType = EncodingType.Default // Encoding type for password hashing
};
```
### Check password (When GeneratePerPasswordSalt is true)
```C#
//Combine the user object and HashConfig object (When GeneratePerPasswordSalt is true)
//Create method to check password
public void ValidatePassword()
{
var userObject = new User
{
EmailId = "[email protected]",
Password = "Test#11"
};
var hashConfig = new HashingConfig
{
GeneratePerPasswordSalt = true,
GlobalSalt = null,
SaltedPasswordFormat = "#PasswordPlaceHolder#--#SaltPlaceHolder#",
HashingAlgo = HashingAlgo.MD5,
PasswordHashEncodingType = EncodingType.Default
};
var passwordHashing = new PasswordHashing(); // Create password hashing object
var hash = passwordHashing.GetHash(userObject.Password, hashConfig); // GetHash for the password
var match = passwordHashing.CheckPassword(hash, hashConfig, userObject.Password); //Check password
}
```### Example 2 - Create HashConfig object (When GeneratePerPasswordSalt is false)
```C#
//In that case we have to set the GlobalSalt property
//Create HashConfig object and set below properties
var hashConfig = new HashingConfig
{
GeneratePerPasswordSalt = false, \
GlobalSalt = SecureSalt,
SaltedPasswordFormat = "#PasswordPlaceHolder#--#SaltPlaceHolder#",
HashingAlgo = HashingAlgo.MD5,
PasswordHashEncodingType = EncodingType.Default
};
```
### Check password (When GeneratePerPasswordSalt is false)
```C#
//Combine the user object and HashConfig object (When GeneratePerPasswordSalt is false)
//Create method to check password
public void ValidatePassword()
{
var userObject = new User
{
EmailId = "[email protected]",
Password = "Test#11"
};
var hashConfig = new HashingConfig
{
GeneratePerPasswordSalt = false,
GlobalSalt = "SecureSalt",
SaltedPasswordFormat = "#PasswordPlaceHolder#--#SaltPlaceHolder#",
HashingAlgo = HashingAlgo.MD5,
PasswordHashEncodingType = EncodingType.Default
};
var passwordHashing = new PasswordHashing(); // Create password hashing object
var hash = passwordHashing.GetHash(userObject.Password, hashConfig); // GetHash for the password
var match = passwordHashing.CheckPassword(hash, hashConfig, userObject.Password); //Check password
}
```## Contributing
Would love any contributions by you, including better documentation, tests or more robust functionality. Please follow the [contributing guide](CONTRIBUTING.md)## License
[MIT](LICENSE)