Skip to content

Instantly share code, notes, and snippets.

@netstart
Created March 9, 2020 13:00
Show Gist options
  • Save netstart/9ffa5b2bee1368adf2f2ec8889131885 to your computer and use it in GitHub Desktop.
Save netstart/9ffa5b2bee1368adf2f2ec8889131885 to your computer and use it in GitHub Desktop.

Revisions

  1. netstart created this gist Mar 9, 2020.
    15 changes: 15 additions & 0 deletions Password.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

    public class Password {
    public User changePassword(String newClearPassword) {
    BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    if (!passwordEncoder.matches(newClearPassword, this.getPassword())) {
    throw new InvalidPasswordException();
    }

    this.password(passwordEncoder, newClearPassword);

    return this;
    }
    }