This system hashes passwords using a version of Bruce Schneier's Blowfish block cipher with modifications designed to raise the cost of off-line password cracking. The computation cost of the algorithm is parameterised, so it can be increased as computers and Dart VM get faster.
Add to your pubspec.yaml the following:
dependencies:
dbcrypt: ^1.0.0
Hashing a password is easy:
import 'package:dbcrypt/dbcrypt.dart'
main() {
var plainPassword = "P@55w0rd";
var hashedPassword = new DBCrypt().hashpw(plainPassword, new DBCrypt().gensalt());
}
Comparing a plain and a hashed password is even easier:
var isCorrect = new DBCrypt().checkpw(plain, hashed);
Dependencies are installed using the Pub Package Manager.
# For running the tests it needs the 'dart' executable on your path.
# Execute the next command if it isn't already on your path:
export DART_SDK=path/to/dart/sdk
pub install
test/run.sh
example/example.dart
import 'package:dbcrypt/dbcrypt.dart';
void main() {
DBCrypt dBCrypt = DBCrypt();
const plainPwd = "mySuperSecretP@ssw0rd";
// Hash password with default values
String hashedPwd = dBCrypt.hashpw(plainPwd, dBCrypt.gensalt());
// Check the plain password against the hashed password
assert(dBCrypt.checkpw(plainPwd, hashedPwd), true);
// Generate a salt with a cost of 12 and hash the password with it
String salt = dBCrypt.gensaltWithRounds(12);
hashedPwd = dBCrypt.hashpw(plainPwd, salt);
// Check the plain password against the 12-cost hashed password
assert(dBCrypt.checkpw(plainPwd, hashedPwd), true);
}
Add this to your package's pubspec.yaml file:
dependencies:
dbcrypt: ^1.0.0
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:dbcrypt/dbcrypt.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.0.0 | Aug 2, 2018 |
|
|
0.2.1 | Dec 7, 2013 |
|
|
0.2.0 | Nov 7, 2013 |
|
|
0.1.3+2 | May 4, 2013 |
|
|
0.1.3+1 | Apr 11, 2013 |
|
|
0.1.3 | Apr 4, 2013 |
|
|
0.1.2 | Mar 9, 2013 |
|
|
0.1.1 | Feb 21, 2013 |
|
|
0.1.0 | Jan 26, 2013 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
84
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
90
|
Overall:
Weighted score of the above.
[more]
|
90
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:dbcrypt/dbcrypt.dart
.
The description is too long. (-10 points)
Search engines display only the first part of the description. Try to keep the value of the description
field in your package's pubspec.yaml
file between 60 and 180 characters.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.24.0 <3.0.0 | ||
Dev dependencies | |||
benchmark_harness | >=1.0.2 <2.0.0 | ||
test | ^1.3.0 |