Skip to content

Commit 17ca04f

Browse files
Use random string name
1 parent e276a88 commit 17ca04f

File tree

13 files changed

+523
-524
lines changed

13 files changed

+523
-524
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github: stfn
1+
github: stfndamjanovic

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Ask a question
4-
url: https://github.com/stfn/random-hash/discussions/new?category=q-a
4+
url: https://github.com/stfndamjanovic/php-random-string/discussions/new?category=q-a
55
about: Ask the community for help
66
- name: Request a feature
7-
url: https://github.com/stfn/random-hash/discussions/new?category=ideas
7+
url: https://github.com/stfndamjanovic/php-random-string/discussions/new?category=ideas
88
about: Share ideas for new features
99
- name: Report a security issue
10-
url: https://github.com/stfn/random-hash/security/policy
10+
url: https://github.com/stfndamjanovic/php-random-string/security/policy
1111
about: Learn how to notify us for sensitive bugs

.github/dependabot.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/dependabot-auto-merge.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Changelog
22

3-
All notable changes to `random-hash` will be documented in this file.
3+
All notable changes to `php-random-string` will be documented in this file.
44

README.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# Random hash generator for PHP
1+
# Random string generator for PHP
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/stfn/php-random-hash.svg?style=flat-square)](https://packagist.org/packages/stfn/random-hash)
4-
[![Tests](https://img.shields.io/github/actions/workflow/status/stfn/php-random-hash/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/stfn/random-hash/actions/workflows/run-tests.yml)
5-
[![Total Downloads](https://img.shields.io/packagist/dt/stfn/php-random-hash.svg?style=flat-square)](https://packagist.org/packages/stfn/random-hash)
3+
[![Tests](https://img.shields.io/github/actions/workflow/status/stfndamjanovic/php-random-string/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/stfndamjanovic/php-random-string/actions/workflows/run-tests.yml)
64

75
Description
86

@@ -11,33 +9,55 @@ Description
119
You can install the package via composer:
1210

1311
```bash
14-
composer require stfn/php-random-hash
12+
composer require stfn/php-random-string
1513
```
1614

1715
## Usage
1816

17+
Simple example without any configuration.
18+
1919
```php
20-
use Stfn\RandomHash\HashConfig;
21-
use Stfn\RandomHash\RandomHash;
20+
use Stfn\RandomString\RandomString;
21+
22+
$string = RandomString::new()->generate();
23+
24+
echo $string; // Output: RIKdjFzuDaN12RiJ
25+
```
26+
27+
If you want to generate string consist of numbers only, you can do it like this:
28+
```php
29+
use Stfn\RandomString\StringConfig;
30+
use Stfn\RandomString\RandomString;
31+
32+
$config = StringConfig::make()->length(6)->numbersOnly();
2233

23-
$config = HashConfig::make()
24-
->length(6)
25-
->numbersOnly()
26-
->skip(function ($hash) {
27-
return in_array($hash, ['034522', '109487']);
28-
});
34+
$string = RandomString::fromConfig($config)->generate();
2935

30-
$hashes = RandomHash::make($config)->generate();
36+
echo $string; // Output: 649432
3137
```
3238

33-
This example will skip 034522 and 109487 and generate 6 character hash consist of numbers only.
39+
Or you can use your custom charset for generating random string:
40+
```php
41+
use Stfn\RandomString\StringConfig;
42+
use Stfn\RandomString\RandomString;
43+
44+
$config = StringConfig::make()->charset("ABCD1234");
45+
46+
$string = RandomString::fromConfig($config)->generate();
47+
48+
echo $string; // Output: 3B41B32C2A12A3A1
49+
```
3450

3551
## Testing
3652

3753
```bash
3854
composer test
3955
```
4056

57+
## Security
58+
59+
While the RandomString class is designed to generate random and unpredictable string, it is important to note that it is not a cryptographically secure hash function and should not be used for sensitive applications such as password hashing or cryptographic key generation.
60+
4161
## Changelog
4262

4363
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

composer.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"name": "stfn/random-hash",
3-
"description": "This is my package random-hash",
2+
"name": "stfn/php-random-string",
3+
"description": "",
44
"keywords": [
55
"stfn",
6-
"random-hash"
6+
"random-string"
77
],
8-
"homepage": "https://github.com/stfn/random-hash",
8+
"homepage": "https://github.com/stfn/php-random-string",
99
"license": "MIT",
1010
"authors": [
1111
{
@@ -19,22 +19,21 @@
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^9.5",
22-
"laravel/pint": "^1.2",
23-
"spatie/ray": "^1.28"
22+
"laravel/pint": "^1.2"
2423
},
2524
"autoload": {
2625
"psr-4": {
27-
"Stfn\\RandomHash\\": "src"
26+
"Stfn\\RandomString\\": "src"
2827
}
2928
},
3029
"autoload-dev": {
3130
"psr-4": {
32-
"Stfn\\RandomHash\\Tests\\": "tests"
31+
"Stfn\\RandomString\\Tests\\": "tests"
3332
}
3433
},
3534
"scripts": {
3635
"test": "vendor/bin/phpunit",
37-
"test-coverage": "vendor/bin/phpunit --coverage",
36+
"test-coverage": "vendor/bin/phpunit --coverage",
3837
"format": "vendor/bin/pint"
3938
},
4039
"config": {

src/InvalidConfigException.php renamed to src/InvalidStringConfigException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
namespace Stfn\RandomHash;
3+
namespace Stfn\RandomString;
44

55
use Exception;
66

7-
class InvalidConfigException extends Exception
7+
class InvalidStringConfigException extends Exception
88
{
99
public static function maxCombinationReached()
1010
{
11-
return new self('Cannot generate hash because there is no more possible combinations. Check your config.');
11+
return new self('Cannot generate string because there is no more possible combinations. Check your config.');
1212
}
1313

1414
public static function invalidCharset()

src/RandomHash.php

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)