Coder Social home page Coder Social logo

quondam's Introduction

Quondam

A Latin word meaning "one-time" (if you squint a bit).

This library is a one-time password generation & validation library I wrote for a job application. The spec was to have a C# library or program capable of:

  • Generating a one-time password for any given user name.
  • Validating the password by sending a user name and password.
  • Expiring passwords after 30 seconds if they aren't used

This solution uses NUnit for testing and NLog for creating an audit trail of failed login attempts. I salt and hash passwords before storing them. There is no persistence layer for the passwords - everything is in memory.

Testing with timings

I've used a pattern I find myself repeatedly recreating for doing unit tests involving timing. It looks like this:

internal interface IClock
{
    DateTime Now { get; }
}

public PasswordManager()
    : this(new RealClock()) { }
internal PasswordManager(IClock clock)
{
    this.clock = clock;
}

This allows me to use a real clock (an implementation that just returns System.DateTime.Now) in production, but mock out the clock with something under the control of the unit tests when testing.

TDD or not to TDD?

The commits here are a pretty good example of my normal programming habits: A mixture of writing first interfaces, then tests, then an implementation (strict TDD), as well as writing implementations first and then tests afterwards. For example, the first four commits have no implementation, just tests. Then, in commit 5 I implement PasswordManager. In doing so, I discover that I need some helper classes (UserStore and PasswordRecord). So in commit 6 I then write tests for these new classes.

I find this mixed approach works well, giving me both formality and upfront contracts with tests, but also the flexibility to sometimes discover through exploration.

quondam's People

Watchers

James Cloos avatar

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.