Giter VIP home page Giter VIP logo

jkbcrypt's Introduction

JKBCrypt

JKBCrypt is an implementation of bcrypt written in Swift. It currently is able to generate the salt and hash a phrase using a generated salt.

Importing the Code

Import the files from the lib/ directory into your Swift project where you feel is appropriate. Eventually, I'd like to get this project into a CocoaPod, but this has not happened yet.

Using the Code

JKBCrypt.generateSaltWithNumberOfRounds(rounds: UInt) -> String
JKBCrypt.generateSalt() -> String
JKBCrypt.hashPassword(password: String, withSalt salt: String) -> String?
JKBCrypt.verifyPassword(password: String, matchesHash hash: String) -> Bool?

The generateSaltWithNumberOfRounds() class function will generate a random salt using the number of rounds provided. The number of rounds must be between 4 and 31 inclusively.

The generateSalt() class convenience function will generate a random salt using a default 10 rounds. This number can be adjusted based on your specific needs.

The hashPassword(withSalt:) class function will hash the password phrase using the salt. If there is an issue during processing, nil will be returned. Check the function documentation for details.

The verifyPassword(matchesHash:) class convenience function will hash the password phrase using the hash, then return the comparison between the new hash and the given hash. If there is an issue during processing, nil will be returned. Check the function documentation for details.

Example

There is an example Xcode project that uses the JKBCrypt functions to calculate salts, hashes, and compare hashes. See the example project for a better understanding on how to use the functions.

Roadmap

Testing

Provide suitable unit tests for the functions in the JKBCrypt and JKBCryptRandom classes.

Optimization

The code was written using Swift 1.2 and has not been run against Swift 2.0 yet. The code was optimized by using UnsafePointer<Type> for much of the array indexing but is still significantly slower than bcrypt running in Objective-C on the same machine (Objective-C: ~0.2s/10 rnds; Swift: 4-5s/10 rnds).

CocoaPods

Create a pod for this code for easy imports and updates.

Issues, Bugs, etc.

If you have any issues, bugs, or feature suggestions, please create an issue.

Credits

This project was inspired by and based on the Objective-C port by Jay Fuerstenberg (Git Repo).

The Objective-C port is based on the original Java implementation by Damien Miller found here.

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.