| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="IdentityFaker.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Text; |
| | | 9 | | using MyNet.Fakers.Text; |
| | | 10 | | using MyNet.Generator; |
| | | 11 | | |
| | | 12 | | namespace MyNet.Fakers.Identity; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Current implementation of <see cref="IIdentityFaker"/>. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="random">The random generator instance.</param> |
| | | 18 | | /// <param name="text">The text faker instance.</param> |
| | | 19 | | public sealed class IdentityFaker(IRandomGenerator random, ITextFaker text) : IIdentityFaker |
| | | 20 | | { |
| | | 21 | | /// <inheritdoc /> |
| | 3 | 22 | | public string Username() => $"{text.Word()}{random.Int(100, 9999)}"; |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | | 25 | | public string Password(int length = 12) |
| | | 26 | | { |
| | 3 | 27 | | ArgumentOutOfRangeException.ThrowIfNegative(length); |
| | | 28 | | |
| | 3 | 29 | | var builder = new StringBuilder(length); |
| | | 30 | | |
| | 36 | 31 | | for (var i = 0; i < length; i++) |
| | 15 | 32 | | builder.Append((char)random.Int(33, 127)); |
| | | 33 | | |
| | 3 | 34 | | return builder.ToString(); |
| | | 35 | | } |
| | | 36 | | } |
| | | 37 | | |