Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
more nullchecking
Browse files Browse the repository at this point in the history
  • Loading branch information
jerptrs committed Jun 9, 2021
1 parent 0ac33bc commit e7d1311
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 2 additions & 0 deletions MooveTeq-Booking.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=cleartext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Consts/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UserDictionary/Words/=Moove/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=NOCASE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sqlite/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
4 changes: 0 additions & 4 deletions MooveTeq-Booking/Data/DistanceChosenEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MooveTeqBooking.Data {
public class DistanceChosenEventArgs : EventArgs {
Expand Down
12 changes: 5 additions & 7 deletions MooveTeq-Booking/Data/MapsApi.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GoogleMapsApi;
using GoogleMapsApi.Entities.Common;
using GoogleMapsApi.Entities.Directions.Request;
using GoogleMapsApi.Entities.Directions.Response;
using static GoogleMapsApi.GoogleMaps;

namespace MooveTeqBooking.Data {
class MapsApi {
internal static class MapsApi {
/// <summary>
/// Returns the distance in meters between two physical places or addresses.
/// </summary>
Expand All @@ -25,9 +22,10 @@ public static async Task<int> GetDistanceBetweenTwoAddresses(string originAddres
ApiKey = "AIzaSyCtdj4v-sr8-8x9-qtoOTSyKU9KFq8Vao8"
};

var directions = await GoogleMaps.Directions.QueryAsync(directionsRequest);
// ReSharper disable once PossibleNullReferenceException
var directions = await Directions?.QueryAsync(directionsRequest);

if (directions.Status != DirectionsStatusCodes.OK) {
if (directions != null && directions.Status != DirectionsStatusCodes.OK) {
throw new Exception(directions.Status.ToString());
}

Expand Down
11 changes: 7 additions & 4 deletions MooveTeq-Booking/Data/PasswordHashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
using System.Text.RegularExpressions;

namespace MooveTeqBooking.Data {
internal class PasswordHashing {
internal static class PasswordHashing {
private const int SaltSize = 24; // size in bytes
private const int Iterations = 5000; // number of pbkdf2 iterations

public static string GetPasswordHash(string cleartextPassword, byte[] existingSalt = null) {
// Generate a salt
var salt = new byte[SaltSize];
byte[] salt;
if (existingSalt is null) {
var provider = new RNGCryptoServiceProvider();
salt = new byte[SaltSize];
Expand All @@ -24,9 +24,12 @@ public static string GetPasswordHash(string cleartextPassword, byte[] existingSa
return Convert.ToBase64String(salt) + ":" + Convert.ToBase64String(pbkdf2.GetBytes(64));
}

public static bool TestPasswordAgainstHash(string cleartextPassword, string hash) {
public static bool TestPasswordAgainstHash(string cleartextPassword, string hash)
{
_ = hash ?? throw new ArgumentNullException(nameof(hash));

var matches = Regex.Match(hash, @"^([A-Za-z0-9+=/]+):([A-Za-z0-9+=/]+)$");
byte[] salt = Convert.FromBase64String(matches.Groups[1].Value);
var salt = Convert.FromBase64String(matches.Groups[1].Value);

var hashedPassword = GetPasswordHash(cleartextPassword, salt);

Expand Down
9 changes: 5 additions & 4 deletions MooveTeq-Booking/Data/TripInformation.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MooveTeqBooking.Data {
public class TripInformation {
Expand All @@ -16,10 +12,15 @@ public enum BookingType {
}

public BookingType BillTripBy { get; set; }

public double? DrivenDistance { get; set; }

public double? TotalDistance { get; set; }

public TimeSpan? TotalTime { get; set; }

public DateTime TripStartTime { get; set; }

public DateTime TripEndTime { get; set; }
}
}

0 comments on commit e7d1311

Please sign in to comment.