Skip to content

Do passwords need to be null terminated? #76

@alanhe

Description

@alanhe

When password has more than 72 bytes, it is truncated and the assumption may not hold true.
I wonder if L109 is necessary.

rust-bcrypt/src/lib.rs

Lines 106 to 114 in b6af5e5

// Passwords need to be null terminated
let mut vec = Vec::with_capacity(password.len() + 1);
vec.extend_from_slice(password);
vec.push(0);
// We only consider the first 72 chars; truncate if necessary.
// `bcrypt` below will panic if len > 72
let truncated = if vec.len() > 72 { &vec[..72] } else { &vec };
let output = bcrypt::bcrypt(cost, salt, truncated);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions