-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Final Code, but not ready to merge] Credentials Table #1597
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d355abb
Added Credential entity
analogrelay 398aeec
Rewrote FindByUserNameAndPassword to use creds
analogrelay 467ef53
Rewrote FindByUserNameOrEmailAndPassword
analogrelay 37bd44d
Added AuthenticateCredential service method
analogrelay 8ca55ba
Started on ReplaceCredential
analogrelay 0bdae2e
Added tests for AuthenticateCredential
analogrelay 4f3b9a4
Fixed up Create/Delete/PublishPackage APIs
analogrelay cfe5e8e
Finished adding Api tests for new creds table
analogrelay 67060ab
Updated GenerateApiKey action to use new table
analogrelay c6eb576
Changed GenerateApiKey action to update old col
analogrelay d8ea0c7
Updated Password-management service methods
analogrelay 264e173
Rescaffolded CredentialsTable migration
analogrelay d56ecee
Fixed Account action to display API Key from cred
analogrelay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public class Credential : IEntity | ||
{ | ||
public Credential() { } | ||
|
||
public Credential(string type, string value) | ||
{ | ||
Type = type; | ||
Value = value; | ||
} | ||
|
||
public int Key { get; set; } | ||
|
||
[Required] | ||
public int UserKey { get; set; } | ||
|
||
[Required] | ||
[StringLength(maximumLength: 64)] | ||
public string Type { get; set; } | ||
|
||
[StringLength(maximumLength: 256)] | ||
public string Identifier { get; set; } | ||
|
||
[Required] | ||
[StringLength(maximumLength: 256)] | ||
public string Value { get; set; } | ||
|
||
public virtual User User { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace NuGetGallery | ||
{ | ||
/// <summary> | ||
/// Provides helper methods to generate credentials. | ||
/// </summary> | ||
public static class CredentialBuilder | ||
{ | ||
public static Credential CreateV1ApiKey() | ||
{ | ||
return CreateV1ApiKey(Guid.NewGuid()); | ||
} | ||
|
||
public static Credential CreateV1ApiKey(Guid apiKey) | ||
{ | ||
var value = apiKey | ||
.ToString() | ||
.ToLowerInvariant(); | ||
return new Credential(Constants.CredentialTypes.ApiKeyV1, value); | ||
} | ||
|
||
public static Credential CreatePbkdf2Password(string plaintextPassword) | ||
{ | ||
return new Credential( | ||
Constants.CredentialTypes.PasswordPbkdf2, | ||
CryptographyService.GenerateSaltedHash(plaintextPassword, Constants.PBKDF2HashAlgorithmId)); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/NuGetGallery/Migrations/201309172217450_CredentialsTable.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
src/NuGetGallery/Migrations/201309172217450_CredentialsTable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace NuGetGallery.Migrations | ||
{ | ||
using System; | ||
using System.Data.Entity.Migrations; | ||
|
||
public partial class CredentialsTable : DbMigration | ||
{ | ||
public override void Up() | ||
{ | ||
CreateTable( | ||
"dbo.Credentials", | ||
c => new | ||
{ | ||
Key = c.Int(nullable: false, identity: true), | ||
UserKey = c.Int(nullable: false), | ||
Type = c.String(nullable: false, maxLength: 64), | ||
Identifier = c.String(maxLength: 256), | ||
Value = c.String(nullable: false, maxLength: 256), | ||
}) | ||
.PrimaryKey(t => t.Key) | ||
.ForeignKey("dbo.Users", t => t.UserKey, cascadeDelete: true) | ||
.Index(t => t.UserKey); | ||
|
||
CreateIndex( | ||
"dbo.Credentials", | ||
new[] { "Type", "Value" }, | ||
unique: true, | ||
name: "IX_Credentials_Type_Value"); | ||
} | ||
|
||
public override void Down() | ||
{ | ||
DropIndex("dbo.Credentials", new[] { "UserKey" }); | ||
DropIndex("dbo.Credentials", "IX_Credentials_Type_Value"); | ||
DropForeignKey("dbo.Credentials", "UserKey", "dbo.Users"); | ||
DropTable("dbo.Credentials"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The credential type can be any string, but this sets a vague precedent for "[type].[subtype]". For example, if we decided to use a different password hashing algorithm (ROT13, for example), we'd use "password.rot13". Similarly, if we decide to rev API keys to be hashed, we'd use "apikey.v2"