-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathuser-credentials.js
More file actions
57 lines (52 loc) · 1.32 KB
/
user-credentials.js
File metadata and controls
57 lines (52 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* www-authenticate
* https://github.com/randymized/www-authenticate
*
* Copyright (c) 2013 Randy McLaughlin
* Licensed under the MIT license.
*/
/*
* Copyright © 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var md5= require('./md5');
/*
* Hide the password. Uses the password to form authorization strings,
* but provides no interface for exporting it.
*/
function user_credentials(username,password,options) {
if (username.is_user_credentials &&
typeof username.basic === 'function' &&
typeof username.digest === 'function'
) {
return username;
}
var basic_string= options && options.hide_basic ?
''
:
(!password && password !== '' ?
Buffer.from(username, "ascii").toString("base64")
:
Buffer.from(username+':'+password, "ascii").toString("base64")
)
function Credentials()
{
this.username= username;
}
Credentials.prototype.basic= function()
{
return basic_string;
}
Credentials.prototype.digest= function(realm)
{
return !password && password !== '' ?
md5(username+':'+realm)
:
md5(username+':'+realm+':'+password)
}
Credentials.prototype.is_user_credentials= function()
{
return true;
}
return new Credentials;
}
module.exports= user_credentials;