Passwort Security und son kram

This commit is contained in:
Waldi
2016-12-22 09:43:35 +01:00
parent 86dd64935a
commit fce5060290
20 changed files with 478 additions and 5 deletions

View File

@@ -593,6 +593,7 @@
<Compile Include="ViewModel\EmployeeAPPCodeVM.cs" />
<Compile Include="ViewModel\ChatMessageVM.cs" />
<Compile Include="ViewModel\ChatMediaMessageVM.cs" />
<Compile Include="ViewModel\PasswortVerlaufVM.cs" />
<Compile Include="ViewModel\ListViewModel\BargeldkassenListVM.cs" />
<Compile Include="ViewModel\ListViewModel\MedRecordListVM.cs" />
<Compile Include="ViewModel\ListViewModel\SupportConceptApprovalPeriodEmployeeRelListVM.cs" />

View File

@@ -67,6 +67,8 @@ namespace BeWo
private static DocumentWatcher _DocumentWatcher;
internal static PasswortSecurityStrength PasswortStrength;
public static BeWoApp CurrentBeWo
{
get { return Current as BeWoApp; }

View File

@@ -1766,5 +1766,76 @@ namespace BeWo.Core
BeWoApp.MainControl.EndWaiting();
}
public static PasswortSecurityStrength CheckPasswotrSecurity(string paswd)
{
string zahlen = "0123456789";
string grossBuchstaben = "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ";
string kleinBuchstaben = "abcdefghijklmnopqrstuvwxyzäöüß";
string sonderzeichenLevel1 = "\\\"\'µ@€!&/()=?+#*";
string sonderzeichenLevel2 = ",.-;:_><|§$%'{[]}´`^°~²³";
int punkte = 0;
if (paswd.Any(x => grossBuchstaben.Contains(x)))
{
punkte++;
}
if (paswd.Any(x => kleinBuchstaben.Contains(x)))
{
punkte++;
}
if (paswd.Any(x => zahlen.Contains(x)))
{
punkte++;
}
if (paswd.Any(x => sonderzeichenLevel1.Contains(x)))
{
punkte++;
}
if (paswd.Any(x => sonderzeichenLevel2.Contains(x)))
{
punkte++;
}
//passwortlänge
if (paswd.Length >= 6 && paswd.Length < 9)
{
punkte += 1;
}
if (paswd.Length >= 9 && paswd.Length < 12)
{
punkte += 2;
}
if (paswd.Length >= 12 && paswd.Length < 18)
{
punkte += 3;
}
if (paswd.Length >= 18)
{
punkte += 4;
}
//return rückgabe schwach mittel stark
if (punkte > 7)
{
return PasswortSecurityStrength.Stark;
}
else if (punkte > 5 && punkte <= 7)
{
return PasswortSecurityStrength.Mittelmass;
}
else
{
return PasswortSecurityStrength.Schwach;
}
}
}
}

View File

@@ -757,6 +757,8 @@ namespace BeWo
BeWoApp.UserName = lUserName;
BeWoApp.UserPassword = lPassword;
BeWoApp.PasswortStrength = BeWoUtils.CheckPasswotrSecurity(lPassword);
ServiceFacade.DoUserServiceAsync(s2 => s2.LoadUserByLoginName(lUserName),
r2 =>

View File

@@ -717,7 +717,6 @@ namespace BeWo
NavigateTo(_HomeView);
// VarFieldListVM v = new VarFieldListVM(l);
// NavigateTo(new VarFieldView(v));

View File

@@ -200,7 +200,16 @@
<GroupBox.Header>
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
<TextBox x:Name="txtHeader" Margin="3,3,0,0" Background="{x:Null}" Foreground="{DynamicResource MainGroupBoxForegroundBrush}" FontSize="22" BorderBrush="{x:Null}" VerticalAlignment="Center" Padding="0,0,0,0" IsReadOnly="True" />
<TextBlock x:Name="txtChangePassword" VerticalAlignment="Center" Foreground="{DynamicResource MainGroupBoxForegroundBrush}" Margin="5,3,3,3">
<!-- ########################################### Achtung Schloss ################################################################################################## -->
<TextBlock x:Name="txtPasswortSchloss" VerticalAlignment="Center" Margin="5,3,3,3" Foreground="Black" ToolTip="Passwort Sicherheit Onlinehilfe">
<Hyperlink RequestNavigate="PasswortAendernLinkOnRequestNavigate" NavigateUri="#" Foreground="Black" TextDecorations="None">
<TextBlock x:Name="PasswortSchloss" Text="" HorizontalAlignment="Center" Foreground="OrangeRed" FontSize="12" VerticalAlignment="Center" />
</Hyperlink>
</TextBlock>
<!-- ############################################################################################################################################################## -->
<TextBlock x:Name="txtChangePassword" VerticalAlignment="Center" Foreground="{DynamicResource MainGroupBoxForegroundBrush}" Margin="5,3,3,3">
<Hyperlink RequestNavigate="PasswortAendernLinkOnRequestNavigate" NavigateUri="#" Foreground="{DynamicResource MainGroupBoxForegroundBrush}">
<TextBlock Text="Passwort ändern" HorizontalAlignment="Center" Foreground="{DynamicResource MainGroupBoxForegroundBrush}" FontSize="12" VerticalAlignment="Center" />
</Hyperlink>

View File

@@ -38,6 +38,7 @@ using System.Media;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using BS.Shared.Core;
using Newtonsoft.Json;
@@ -91,17 +92,20 @@ namespace BeWo.View
//################################################################
//int staerke
public HomeDragPanelView()
{
InitializeComponent();
txtHeader.Text = String.Format("{0} {1}", BeWoApp.LoggedOnUser.Employee.FirstName,
BeWoApp.LoggedOnUser.Employee.LastName);
txtHeader.Text = String.Format("{0} {1}", BeWoApp.LoggedOnUser.Employee.FirstName,BeWoApp.LoggedOnUser.Employee.LastName);
txtVersion.Text = BeWoApp.Version;
txtLoginTime.Text = string.Empty;
txtLastLoginTime.Text = string.Empty;
PasswortSchloss.Text = string.Join("", (from Match m in Regex.Matches("D83DDD12", @"\S{4}") select (char)int.Parse(m.Value, NumberStyles.HexNumber)).ToArray());
//PreparePanels();
InitPanels(null);
@@ -146,6 +150,53 @@ namespace BeWo.View
{
BewoChat.Visibility = Visibility.Hidden;
}
PruefePasswortStaerke();
}
private void PruefePasswortStaerke()
{
if (BeWoApp.PasswortStrength == PasswortSecurityStrength.Schwach)
{
PasswortSchloss.Foreground = new SolidColorBrush(Colors.Red);
this.Dispatcher.BeginInvoke(
DispatcherPriority.Normal,
(Action)delegate
{
if (BeWoApp.AppSettings.IsPasswordSecurityActiv)
{
MessageBox.Show("Ihr Passwort ist zu Schwach, bitte ändern sie es bei gelegenheit!", "Achtung",
MessageBoxButton.OK);
}
});
}else if (BeWoApp.PasswortStrength == PasswortSecurityStrength.Mittelmass)
{
PasswortSchloss.Foreground = new SolidColorBrush(Colors.Yellow);
//this.Dispatcher.BeginInvoke(
//DispatcherPriority.Normal,
//(Action)delegate
//{
// if (BeWoApp.AppSettings.IsPasswordSecurityActiv)
// {
// MessageBox.Show("Ihr Passwort ist zu Schwach, bitte ändern sie es bei gelegenheit!", "Achtung",
// MessageBoxButton.OK);
// }
//});
}else if (BeWoApp.PasswortStrength == PasswortSecurityStrength.Stark)
{
PasswortSchloss.Foreground = new SolidColorBrush(Colors.Green);
}
//wenn passwortsicherheit zusätzlich aktiviert dann gib messagebox aus (ihr passwort ist zu Schwach)
}
private void PreparePanels()

View File

@@ -181,7 +181,6 @@ namespace BeWo.View
}
else
{
//Passwort Längen Bonus Punkte
if (NeuesPwBox.Password.Length >= 6 && NeuesPwBox.Password.Length < 9 )
{

View File

@@ -0,0 +1,70 @@
using BS.Shared;
using BS.Shared.DataContracts;
using System;
namespace BeWo.ViewModel
{
public class PasswortVerlaufVM : AbstractDCMapperVM<PasswortVerlaufDC>
{
public static string PropertyName_ErstellDatum = "ErstellDatum";
//Nein zu Passwort und Salt
private DateTime _ErstellDatum;
private long? _ApplicationUserOid;
public PasswortVerlaufVM(PasswortVerlaufDC pDC)
: base(pDC, true)
{
}
public DateTime ErstellDatum
{
get { return this._ErstellDatum; }
set
{
if (this.AreDifferent(this._ErstellDatum, value))
{
this._ErstellDatum = value;
this.StoreDirtyInformation(this.AreDifferent(DataContract.ErstellDatum, value), PropertyName_ErstellDatum);
this.FirePropertyChanged(PropertyName_ErstellDatum);
}
}
}
public virtual long? ApplicationUserOid
{
get
{
return this._ApplicationUserOid;
}
set
{
if (this.AreDifferent(this._ApplicationUserOid, value))
{
this._ApplicationUserOid = value;
}
}
}
protected override void InitByDataContract(PasswortVerlaufDC pDataContract)
{
_ApplicationUserOid = pDataContract.ApplicationUserOid;
_ErstellDatum = pDataContract.ErstellDatum;
}
protected override PasswortVerlaufDC MapToDataContract(PasswortVerlaufDC pDataContract, bool doCommit)
{
pDataContract.ErstellDatum = _ErstellDatum;
pDataContract.ApplicationUserOid = _ApplicationUserOid;
return pDataContract;
}
}
}

View File

@@ -158,6 +158,7 @@
<Compile Include="Entities\EmployeeAPPCode.cs" />
<Compile Include="Entities\ChatMessage.cs" />
<Compile Include="Entities\ChatMediaMessage.cs" />
<Compile Include="Entities\PasswortVerlauf.cs" />
<Compile Include="Entities\MedRecord.cs" />
<Compile Include="Entities\NewestChatMessage.cs" />
<Compile Include="Entities\SupportConceptApprovalPeriod2Employee.cs" />
@@ -552,6 +553,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ICD10\icd10gm2012syst_claml_20110923.xml" />
<EmbeddedResource Include="Mappings\PasswortVerlauf.hbm.xml">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Mappings\ChatMediaMessage.hbm.xml">
<SubType>Designer</SubType>
</EmbeddedResource>

View File

@@ -0,0 +1,121 @@
using BS.Shared;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace BeWo.Data.Entities
{
public class PasswortVerlauf : BeWoEntityBase
{
public static string PropertyName_ApplicationUserOid = "ApplicationUserOid";
public static string PropertyName_ErstellDatum = "ErstellDatum";
public static string PropertyName_Passwort = "Passwort";
public static string PropertyName_Salt = "Salt";
private readonly byte[] _Rc2IV = { 35, 138, 177, 253, 227, 63, 2, 27 };
private readonly byte[] _Rc2Key = { 174, 130, 219, 185, 185, 221, 96, 50, 37, 212, 81, 121, 71, 206, 130, 153 };
private string _Passwort;
private DateTime _ErstellDatum;
private long? _ApplicationUserOid;
private string _Salt;
public virtual string Passwort
{
get { return _Passwort; }
set
{
if (AreDifferent(_Passwort, value))
{
_Passwort = value;
}
}
}
public virtual DateTime ErstellDatum
{
get
{
return this._ErstellDatum;
}
set
{
if (this.AreDifferent(this._ErstellDatum, value))
{
this._ErstellDatum = value;
}
}
}
public virtual long? ApplicationUserOid
{
get
{
return this._ApplicationUserOid;
}
set
{
if (this.AreDifferent(this._ApplicationUserOid, value))
{
this._ApplicationUserOid = value;
}
}
}
public virtual string Salt
{
get { return _Salt; }
set
{
if (AreDifferent(_Salt, value))
{
_Salt = value;
}
}
}
public virtual string RC2EncryptedHash
{
get
{
string lResult = string.Empty;
var lRc2CSP = new RC2CryptoServiceProvider();
ICryptoTransform lEncryptor = lRc2CSP.CreateEncryptor(_Rc2Key, _Rc2IV);
using (var msEncrypt = new MemoryStream())
{
using (var csEncrypt = new CryptoStream(msEncrypt, lEncryptor, CryptoStreamMode.Write))
{
byte[] toEncrypt = Encoding.UTF8.GetBytes(Passwort);
csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
csEncrypt.FlushFinalBlock();
byte[] encrypted = msEncrypt.ToArray();
lResult = BitConverter.ToString(encrypted);
}
}
if (!String.IsNullOrEmpty(lResult))
lResult = lResult.Replace("-", "").ToLower();
return lResult;
}
}
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="BeWo.Data.Entities.PasswortVerlauf,BeWo.Data" table="passwortverlauf">
<id name="Oid" column ="Oid" unsaved-value="null">
<generator class="identity" />
</id>
<version type="Int64" column="Version" name="Version" />
<property name="ApplicationUserOid" column="ApplicationUserOid" />
<property name="InsTs" />
<property name="InsUser" />
<property column="Tid" type="BS.Shared.TableID, BS.Shared" name="_Tid" access="field" />
<property name="UdpUser" />
<property name="IsActive" type="BS.Shared.ActivationTypeId, BS.Shared" />
<property name="SystemEntryID" type="BS.Shared.SystemEntryID, BS.Shared" />
<property name="Notice" />
<property name="ErstellDatum" column="ErstellDatum" />
<property name="Passwort" column="Passwort" />
<property name="Salt" column="Salt" />
</class>
</hibernate-mapping>

View File

@@ -0,0 +1,25 @@
CREATE TABLE `1234567890`.`passwortverlauf` (
`Oid` BIGINT(19) NOT NULL
AUTO_INCREMENT COMMENT '',
`ApplicationUserOid` BIGINT(19) NULL COMMENT '',
`Tid` INT(10) NULL COMMENT '',
`Notice` VARCHAR(1024) NULL COMMENT '',
`InsTs`
DATETIME NULL COMMENT '',
`InsUser` VARCHAR(1024) NULL COMMENT '',
`Version`
BIGINT(19) NULL COMMENT '',
`UdpUser` VARCHAR(256) NULL COMMENT '',
`isActive`
TINYINT(4) NULL COMMENT '',
`SystemEntryID` INT(10) NULL COMMENT '',
`ErstellDatum`
DATETIME NULL COMMENT '',
`Passwort` VARCHAR(64) NULL COMMENT '',
`Salt` VARCHAR(128) NULL COMMENT '',
PRIMARY KEY (`Oid`) COMMENT '')
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;

View File

@@ -45,6 +45,8 @@ namespace BeWo.Service.DCEntityMapper
private static CustomerAPPCodeDC_CustomerAPPCode _CustomerAPPCodeDC_CustomerAPPCode;
private static PasswortVerlaufDC_PasswortVerlauf _PasswortVerlaufDC_PasswortVerlauf;
private static ChatMessageDC_ChatMessage _ChatMessageDC_ChatMessage;
private static ChatMediaMessageDC_ChatMediaMessage _ChatMediaMessageDC_ChatMediaMessage;
@@ -521,6 +523,14 @@ namespace BeWo.Service.DCEntityMapper
}
}
public static PasswortVerlaufDC_PasswortVerlauf PasswortVerlaufDC_PasswortVerlauf
{
get
{
return _PasswortVerlaufDC_PasswortVerlauf ?? (_PasswortVerlaufDC_PasswortVerlauf = new PasswortVerlaufDC_PasswortVerlauf());
}
}
public static ChatMessageDC_ChatMessage ChatMessagesDC_ChatMessages
{
get

View File

@@ -0,0 +1,42 @@
using System.IO;
using BeWo.Data.Entities;
using BS.Shared.DataContracts;
namespace BeWo.Service.DCEntityMapper
{
public class PasswortVerlaufDC_PasswortVerlauf : AbstractIDCEntityMapper<PasswortVerlauf, PasswortVerlaufDC>
{
public override PasswortVerlaufDC MergeWithDC(PasswortVerlauf pEntity, PasswortVerlaufDC pDataContract)
{
pDataContract.ApplicationUserOid = pEntity.ApplicationUserOid;
pDataContract.ErstellDatum = pEntity.ErstellDatum;
pDataContract.Passwort = pEntity.Passwort;
pDataContract.Salt = pEntity.Salt;
return pDataContract;
}
public override PasswortVerlauf MergeWithEntity(PasswortVerlaufDC pDataContract, PasswortVerlauf pEntity)
{
pEntity.ApplicationUserOid = pDataContract.ApplicationUserOid;
pEntity.ErstellDatum = pDataContract.ErstellDatum;
pEntity.Passwort = pDataContract.Passwort;
pEntity.Salt = pDataContract.Salt;
return pEntity;
}
protected override bool AreDCAndEntityEqual(PasswortVerlaufDC pDC, PasswortVerlauf pEntity)
{
if (pDC.PasswortVerlaufOid == null)
{
return false;
}
return pDC.PasswortVerlaufOid == pEntity.Oid;
}
}
}

View File

@@ -213,6 +213,7 @@
<Compile Include="DCEntityMapper\EmployeeAPPCodeDC_EmployeeAPPCode.cs" />
<Compile Include="DCEntityMapper\ChatMessageDC_ChatMessage.cs" />
<Compile Include="DCEntityMapper\ChatMediaMessageDC_ChatMediaMessage.cs" />
<Compile Include="DCEntityMapper\PasswortVerlaufDC_PasswortVerlauf.cs" />
<Compile Include="DCEntityMapper\MedRecordDC_MedRecord.cs" />
<Compile Include="DCEntityMapper\SignatureDC_Signature.cs" />
<Compile Include="DCEntityMapper\SupportConceptApprovalPeriodEmployeeRelDC_SupportConceptApprovalPeriod2Employee.cs" />

View File

@@ -45,6 +45,17 @@ namespace BeWo.Service.ServiceImplementations
}
}
//speichere passwort in verlauf
var passwortvelauf = new PasswortVerlauf
{
ApplicationUserOid = lOriginal.Oid,
Passwort = lOriginal.HashedPassword,
Salt = lOriginal.Salt,
ErstellDatum = DateTime.Now
};
DAOFactory.GenericDAO.Insert(passwortvelauf);
DAOFactory.GenericDAO.Update(lOriginal);
return lOriginal.Version.Value;
}

View File

@@ -877,4 +877,11 @@ namespace BS.Shared
Unauthorized,
Unknown
}
public enum PasswortSecurityStrength
{
Schwach,
Mittelmass,
Stark
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace BS.Shared.DataContracts
{
[DataContract]
public class PasswortVerlaufDC : IDataContract
{
[DataMember]
public long? PasswortVerlaufOid { get; set; }
[DataMember]
public long? ApplicationUserOid { get; set; }
[DataMember]
public string Passwort { get; set; }
[DataMember]
public DateTime ErstellDatum { get; set; }
[DataMember]
public string Salt { get; set; }
}
}

View File

@@ -170,6 +170,7 @@
<Compile Include="DataContracts\EmployeeAPPCodeDC.cs" />
<Compile Include="DataContracts\ChatMessageDC.cs" />
<Compile Include="DataContracts\ChatMediaMessageDC.cs" />
<Compile Include="DataContracts\PasswortVerlaufDC.cs" />
<Compile Include="DataContracts\MedRecordDC.cs" />
<Compile Include="DataContracts\SupportConceptApprovalPeriodEmployeeRelDC.cs" />
<Compile Include="DataContracts\WohnheimbuchungEmployeeRelationDC.cs" />