Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Essem
Sharkey
Commits
dc52209c
Commit
dc52209c
authored
1 year ago
by
Insert5StarName
Browse files
Options
Downloads
Patches
Plain Diff
upd: rehash misskey passwords
parent
3bb67eff
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/backend/src/server/api/SigninApiService.ts
+21
-2
21 additions, 2 deletions
packages/backend/src/server/api/SigninApiService.ts
with
21 additions
and
2 deletions
packages/backend/src/server/api/SigninApiService.ts
+
21
−
2
View file @
dc52209c
...
...
@@ -6,6 +6,7 @@
import
{
Inject
,
Injectable
}
from
'
@nestjs/common
'
;
//import bcrypt from 'bcryptjs';
import
*
as
argon2
from
'
argon2
'
;
import
bcrypt
from
"
bcryptjs
"
;
import
*
as
OTPAuth
from
'
otpauth
'
;
import
{
IsNull
}
from
'
typeorm
'
;
import
{
DI
}
from
'
@/di-symbols.js
'
;
...
...
@@ -25,7 +26,22 @@ import { RateLimiterService } from './RateLimiterService.js';
import
{
SigninService
}
from
'
./SigninService.js
'
;
import
type
{
AuthenticationResponseJSON
}
from
'
@simplewebauthn/typescript-types
'
;
import
type
{
FastifyReply
,
FastifyRequest
}
from
'
fastify
'
;
async
function
hashPassword
(
password
:
string
):
Promise
<
string
>
{
return
argon2
.
hash
(
password
);
}
async
function
comparePassword
(
password
:
string
,
hash
:
string
,
):
Promise
<
boolean
>
{
if
(
isOldAlgorithm
(
hash
))
return
bcrypt
.
compare
(
password
,
hash
);
return
argon2
.
verify
(
hash
,
password
);
}
function
isOldAlgorithm
(
hash
:
string
):
boolean
{
// bcrypt hashes start with $2[ab]$
return
hash
.
startsWith
(
"
$2
"
);
}
@
Injectable
()
export
class
SigninApiService
{
constructor
(
...
...
@@ -124,8 +140,11 @@ export class SigninApiService {
const
profile
=
await
this
.
userProfilesRepository
.
findOneByOrFail
({
userId
:
user
.
id
});
// Compare password
const
same
=
await
argon2
.
verify
(
profile
.
password
!
,
password
);
const
same
=
await
comparePassword
(
password
,
profile
.
password
!
);
if
(
same
&&
isOldAlgorithm
(
profile
.
password
!
))
{
profile
.
password
=
await
hashPassword
(
password
);
await
this
.
userProfilesRepository
.
save
(
profile
);
}
const
fail
=
async
(
status
?:
number
,
failure
?:
{
id
:
string
})
=>
{
// Append signin history
await
this
.
signinsRepository
.
insert
({
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment