Coder Social home page Coder Social logo

robertcroteau / yescrypt-net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from petrsnm/yescrypt-net

0.0 2.0 0.0 120 KB

The yescrypt a password-based key derivation function (KDF) and password hashing scheme for .NET

License: Apache License 2.0

C# 100.00%

yescrypt-net's Introduction

Build status nuget

yescrypt-net

.NET implementation of the yescrypt a password-based key derivation function (KDF) and password hashing scheme.

Packaging

Nuget package available here: https://www.nuget.org/packages/yescrypt

Usage

This implementation is suitable for simple validation of passwords against the yescrypt hash that can be found in the /etc/shadow file on modern Linux distos:

$ sudo cat /etc/shadow
...
testuser:$y$j9T$IZUrEbc9oo9gZ28EqoVjI.$HVWJnkX89URubQkrksozeEoBwresP91xRowRD4ynRE9:19389:0:99999:7:::
...

Using the yescrypt value from the line above, you can write code like this to validate testuser's password:

using Fasterlimit.Yescrypt

public static void main(string[] args)
{
    byte[] passwd = Encoding.UTF8.GetBytes("passw0rd");
    if (Yescrypt.CheckPasswd(passwd, "$y$j9T$IZUrEbc9oo9gZ28EqoVjI.$HVWJnkX89URubQkrksozeEoBwresP91xRowRD4ynRE9"))
    {
        Console.WriteLine("Correct");
    }
    else
    {
        Console.WriteLine("Incorrect");
    }
}

The Yescrypt class has two other useful methods:

  • Yescrypt.ChangePasswd(byte[] newpasswd, string encoded) -
    • Input: new password and yescrypt encoded string.
    • Output: yescrypt string with new salt and new password hash (using settings from the encoded input string)
  • Yescrypt.NewPasswd(byte[] newPasswd,YescryptSettings settings)
    • Input: new password and yescrypt settings.
    • Output output: yescrypt string with new salt and password hash

You can also use the raw YescryptKdf class if you want complete control of the KDF.

Limitations

This implementation does not support p>1 (no parallelism ). It does not support ROMs either. Therefore, it is best suited casual checking of passwords and password hash maintenance. It is (obviously) not suitable for proof of work or similar use cases where large numbers of hashes need be calculated with maximum efficiency.

This implementation has been tested with YESCRYPT_RW flavor. This is the flavor you should use anyway. If this code encounters YESCRYPT_WORM hashes... things might break.

Credits

This is a straight port of the "ref" implementation from the original Openwall C sources. I left in comments so that it is easy to compare the c# port with the original C soruces.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.