| 1 | package com.popx.servizio; | |
| 2 | ||
| 3 | import org.mindrot.jbcrypt.BCrypt; | |
| 4 | ||
| 5 | public class SecurityService { | |
| 6 | ||
| 7 | /*@ | |
| 8 | @ public normal_behavior | |
| 9 | @ requires password != null && !password.isEmpty(); | |
| 10 | @ | |
| 11 | @ // L’hash è sempre non nullo e diverso dalla password in chiaro | |
| 12 | @ ensures \result != null; | |
| 13 | @ ensures !\result.equals(password); | |
| 14 | @ | |
| 15 | @ // Un hash valido BCrypt inizia sempre con "$2" | |
| 16 | @ ensures \result.startsWith("$2"); | |
| 17 | @*/ | |
| 18 | public static String hashPassword(String password) { | |
| 19 | int costFactor = 12; | |
| 20 | String salt = BCrypt.gensalt(costFactor); | |
| 21 |
1
1. hashPassword : replaced return value with "" for com/popx/servizio/SecurityService::hashPassword → KILLED |
return BCrypt.hashpw(password, salt); |
| 22 | } | |
| 23 | ||
| 24 | /*@ | |
| 25 | @ public normal_behavior | |
| 26 | @ requires password != null && !password.isEmpty(); | |
| 27 | @ requires hashedPassword != null && !hashedPassword.isEmpty(); | |
| 28 | @ | |
| 29 | @ // L’output è sempre booleano | |
| 30 | @ ensures \result == true || \result == false; | |
| 31 | @*/ | |
| 32 | public static boolean checkPassword(String password, String hashedPassword) { | |
| 33 |
2
1. checkPassword : replaced boolean return with false for com/popx/servizio/SecurityService::checkPassword → KILLED 2. checkPassword : replaced boolean return with true for com/popx/servizio/SecurityService::checkPassword → KILLED |
return BCrypt.checkpw(password, hashedPassword); |
| 34 | } | |
| 35 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 33 |
1.1 2.2 |