40 def authenticate(self, configurationAttributes, requestParameters, step):
42 authenticationService = CdiUtil.bean(AuthenticationService)
45 print "BCrypt Auth. Authenticate for step 1" 47 identity = CdiUtil.bean(Identity)
48 credentials = identity.getCredentials()
50 user_name = credentials.getUsername()
51 user_password = credentials.getPassword()
55 if (StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password)):
56 userService = CdiUtil.bean(UserService)
57 user = userService.getUser(user_name)
58 hashed_stored_pass = user.getAttribute(
"userPassword")
64 for char
in hashed_stored_pass:
69 password_schema = password_schema + char
70 print(
"Password Schema is: " + password_schema)
73 if 'SSHA' in password_schema:
75 logged_in = authenticationService.authenticate(user_name, user_password)
78 elif 'BCRYPT' in password_schema:
80 salt = hashed_stored_pass[8:]
81 salt = salt.split(
"$")[3].strip()
83 salt =
'$2a$08$' + salt
86 challenge = BCrypt.hashpw(user_password,salt)
89 challenge = challenge.split(
"$")[3].strip()
90 stored = hashed_stored_pass.split(
"$")[3].strip()
92 print(
"Challenge Salt+Hash: " + challenge)
93 print(
"Stored Salt+Hash: " + stored)
96 if challenge
in stored:
100 print(
"Updating hash..")
101 user.setAttribute(
"userPassword",user_password)
102 user = userService.updateUser(user)
103 print(
"Logging in..")
106 logged_in = authenticationService.authenticate(user_name)
111 print(
"Unrecognized algorithm: " + password_schema)
116 logged_in = authenticationService.authenticate(user_name)