mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Added transfer properties to Pastes for password transfers.
This commit is contained in:
parent
e4a0bc6f8f
commit
99c0d3a1e3
@ -7,7 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Teknik", "Teknik\Teknik.csp
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{725ABF52-FD44-4682-81BB-D93598787643}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{725ABF52-FD44-4682-81BB-D93598787643}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
GitVersionConfig.yaml = GitVersionConfig.yaml
|
GitVersion.yaml = GitVersion.yaml
|
||||||
README.md = README.md
|
README.md = README.md
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -65,8 +65,18 @@ namespace Teknik.Areas.Paste.Controllers
|
|||||||
// The paste has a password set
|
// The paste has a password set
|
||||||
if (!string.IsNullOrEmpty(paste.HashedPassword))
|
if (!string.IsNullOrEmpty(paste.HashedPassword))
|
||||||
{
|
{
|
||||||
string hashedPass = Helpers.SHA384.Hash(paste.Key, password).ToHex();
|
byte[] passBytes = Helpers.SHA384.Hash(paste.Key, password);
|
||||||
if (string.IsNullOrEmpty(password) || hashedPass != paste.HashedPassword)
|
string hash = passBytes.ToHex();
|
||||||
|
// We need to convert old pastes to the new password scheme
|
||||||
|
if (paste.Transfers.ToList().Exists(t => t.Type == TransferTypes.ASCIIPassword))
|
||||||
|
{
|
||||||
|
hash = Encoding.ASCII.GetString(passBytes);
|
||||||
|
// Remove the transfer types
|
||||||
|
paste.Transfers.Clear();
|
||||||
|
db.Entry(paste).State = EntityState.Modified;
|
||||||
|
db.SaveChanges();
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(password) || hash != paste.HashedPassword)
|
||||||
{
|
{
|
||||||
PasswordViewModel passModel = new PasswordViewModel();
|
PasswordViewModel passModel = new PasswordViewModel();
|
||||||
passModel.Url = url;
|
passModel.Url = url;
|
||||||
|
@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Teknik.Areas.Users.Models;
|
using Teknik.Areas.Users.Models;
|
||||||
using Teknik.Attributes;
|
using Teknik.Attributes;
|
||||||
|
using Teknik.Models;
|
||||||
|
|
||||||
namespace Teknik.Areas.Paste.Models
|
namespace Teknik.Areas.Paste.Models
|
||||||
{
|
{
|
||||||
@ -47,5 +48,7 @@ namespace Teknik.Areas.Paste.Models
|
|||||||
public int MaxViews { get; set; }
|
public int MaxViews { get; set; }
|
||||||
|
|
||||||
public int Views { get; set; }
|
public int Views { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<TransferType> Transfers { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using Microsoft.AspNet.Identity.EntityFramework;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using Teknik.Attributes;
|
using Teknik.Attributes;
|
||||||
|
using Teknik.Models;
|
||||||
|
|
||||||
namespace Teknik.Areas.Users.Models
|
namespace Teknik.Areas.Users.Models
|
||||||
{
|
{
|
||||||
@ -22,7 +23,7 @@ namespace Teknik.Areas.Users.Models
|
|||||||
|
|
||||||
public bool TransferAccount { get; set; }
|
public bool TransferAccount { get; set; }
|
||||||
|
|
||||||
public List<TransferType> Transfers { get; set; }
|
public virtual ICollection<TransferType> Transfers { get; set; }
|
||||||
|
|
||||||
public DateTime JoinDate { get; set; }
|
public DateTime JoinDate { get; set; }
|
||||||
|
|
||||||
|
@ -109,19 +109,19 @@ namespace Teknik.Areas.Users.Utility
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string username = user.Username.ToLower();
|
string username = user.Username.ToLower();
|
||||||
if (user.Transfers.Exists(t => t.Type == TransferTypes.CaseSensitivePassword))
|
if (user.Transfers.ToList().Exists(t => t.Type == TransferTypes.CaseSensitivePassword))
|
||||||
{
|
{
|
||||||
username = user.Username;
|
username = user.Username;
|
||||||
}
|
}
|
||||||
byte[] hashBytes = SHA384.Hash(username, password);
|
byte[] hashBytes = SHA384.Hash(username, password);
|
||||||
string hash = hashBytes.ToHex();
|
string hash = hashBytes.ToHex();
|
||||||
|
|
||||||
if (user.Transfers.Exists(t => t.Type == TransferTypes.ASCIIPassword))
|
if (user.Transfers.ToList().Exists(t => t.Type == TransferTypes.ASCIIPassword))
|
||||||
{
|
{
|
||||||
hash = Encoding.ASCII.GetString(hashBytes);
|
hash = Encoding.ASCII.GetString(hashBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.Transfers.Exists(t => t.Type == TransferTypes.Sha256Password))
|
if (user.Transfers.ToList().Exists(t => t.Type == TransferTypes.Sha256Password))
|
||||||
{
|
{
|
||||||
hash = SHA256.Hash(password, config.Salt1, config.Salt2);
|
hash = SHA256.Hash(password, config.Salt1, config.Salt2);
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ namespace Teknik.Areas.Users.Utility
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<TransferType> transfers = user.Transfers;
|
List<TransferType> transfers = user.Transfers.ToList();
|
||||||
for (int i = 0; i < transfers.Count; i++)
|
for (int i = 0; i < transfers.Count; i++)
|
||||||
{
|
{
|
||||||
TransferType transfer = transfers[i];
|
TransferType transfer = transfers[i];
|
||||||
|
@ -3,8 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using Teknik.Areas.Users.Models;
|
||||||
|
using Teknik.Areas.Paste.Models;
|
||||||
|
|
||||||
namespace Teknik.Areas.Users.Models
|
namespace Teknik.Models
|
||||||
{
|
{
|
||||||
public enum TransferTypes
|
public enum TransferTypes
|
||||||
{
|
{
|
||||||
@ -19,6 +21,8 @@ namespace Teknik.Areas.Users.Models
|
|||||||
|
|
||||||
public TransferTypes Type { get; set; }
|
public TransferTypes Type { get; set; }
|
||||||
|
|
||||||
public List<User> Users { get; set; }
|
public virtual ICollection<User> Users { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Paste> Pastes { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -211,7 +211,7 @@
|
|||||||
<Compile Include="Areas\User\Models\BlogSettings.cs" />
|
<Compile Include="Areas\User\Models\BlogSettings.cs" />
|
||||||
<Compile Include="Areas\User\Models\ResetPasswordVerification.cs" />
|
<Compile Include="Areas\User\Models\ResetPasswordVerification.cs" />
|
||||||
<Compile Include="Areas\User\Models\RecoveryEmailVerification.cs" />
|
<Compile Include="Areas\User\Models\RecoveryEmailVerification.cs" />
|
||||||
<Compile Include="Areas\User\Models\TransferTypes.cs" />
|
<Compile Include="Models\TransferTypes.cs" />
|
||||||
<Compile Include="Areas\User\Models\UploadSettings.cs" />
|
<Compile Include="Areas\User\Models\UploadSettings.cs" />
|
||||||
<Compile Include="Areas\User\Models\UserSettings.cs" />
|
<Compile Include="Areas\User\Models\UserSettings.cs" />
|
||||||
<Compile Include="Areas\User\UserAreaRegistration.cs" />
|
<Compile Include="Areas\User\UserAreaRegistration.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user