1604678520
The main task of a password generator is generating passwords, right? This will be our goal for this final part. First, we will implement some functionality for Input
and Checkbox
components. Then, we will add a few tweaks. After that, we will finally put together the core piece of our password generator, the method for generating passwords! I hope you ready because we have a lot of work to do today. So, without further ado, let’s bring this awesome app to life!
How to Build Password Generator with Electron & React part 1.
How to Build Password Generator with Electron & React part 2.
You can find the password generator app on GitHub and npm.
Let’s start the work on our password generator by adding some key-value pairs to the state
we will need today. Then, we can continue by creating two new methods, one will be for handling inputs and the second for handling checkboxes. Both these methods will have access to state
and update it, will be able to change values for specific keys. State
is defined in src/App/App.jsx
and those two new methods will be defined here as well. So, let’s open this file and start working.
At this moment, our state
contains four key-value pairs, showAdvancedSettings
, showBasicSettings
and showResult
. Let’s add a few more. These will be settingsAsci
, settingsLower
, settingsNumbers
, settingsSpace
and settingsUpper
. All these keys will be boolean and their default value will be false
. We will use these keys for checkboxes and for switching on or off different options for our password generator, listed on the BasicSettings
screen. Let’s stay here for a second because we are not done yet.
#electron #react #design development #javascript
1653475560
msgpack.php
A pure PHP implementation of the MessagePack serialization format.
The recommended way to install the library is through Composer:
composer require rybakit/msgpack
To pack values you can either use an instance of a Packer
:
$packer = new Packer();
$packed = $packer->pack($value);
or call a static method on the MessagePack
class:
$packed = MessagePack::pack($value);
In the examples above, the method pack
automatically packs a value depending on its type. However, not all PHP types can be uniquely translated to MessagePack types. For example, the MessagePack format defines map
and array
types, which are represented by a single array
type in PHP. By default, the packer will pack a PHP array as a MessagePack array if it has sequential numeric keys, starting from 0
and as a MessagePack map otherwise:
$mpArr1 = $packer->pack([1, 2]); // MP array [1, 2]
$mpArr2 = $packer->pack([0 => 1, 1 => 2]); // MP array [1, 2]
$mpMap1 = $packer->pack([0 => 1, 2 => 3]); // MP map {0: 1, 2: 3}
$mpMap2 = $packer->pack([1 => 2, 2 => 3]); // MP map {1: 2, 2: 3}
$mpMap3 = $packer->pack(['a' => 1, 'b' => 2]); // MP map {a: 1, b: 2}
However, sometimes you need to pack a sequential array as a MessagePack map. To do this, use the packMap
method:
$mpMap = $packer->packMap([1, 2]); // {0: 1, 1: 2}
Here is a list of type-specific packing methods:
$packer->packNil(); // MP nil
$packer->packBool(true); // MP bool
$packer->packInt(42); // MP int
$packer->packFloat(M_PI); // MP float (32 or 64)
$packer->packFloat32(M_PI); // MP float 32
$packer->packFloat64(M_PI); // MP float 64
$packer->packStr('foo'); // MP str
$packer->packBin("\x80"); // MP bin
$packer->packArray([1, 2]); // MP array
$packer->packMap(['a' => 1]); // MP map
$packer->packExt(1, "\xaa"); // MP ext
Check the "Custom types" section below on how to pack custom types.
The Packer
object supports a number of bitmask-based options for fine-tuning the packing process (defaults are in bold):
Name | Description |
---|---|
FORCE_STR | Forces PHP strings to be packed as MessagePack UTF-8 strings |
FORCE_BIN | Forces PHP strings to be packed as MessagePack binary data |
DETECT_STR_BIN | Detects MessagePack str/bin type automatically |
FORCE_ARR | Forces PHP arrays to be packed as MessagePack arrays |
FORCE_MAP | Forces PHP arrays to be packed as MessagePack maps |
DETECT_ARR_MAP | Detects MessagePack array/map type automatically |
FORCE_FLOAT32 | Forces PHP floats to be packed as 32-bits MessagePack floats |
FORCE_FLOAT64 | Forces PHP floats to be packed as 64-bits MessagePack floats |
The type detection mode (
DETECT_STR_BIN
/DETECT_ARR_MAP
) adds some overhead which can be noticed when you pack large (16- and 32-bit) arrays or strings. However, if you know the value type in advance (for example, you only work with UTF-8 strings or/and associative arrays), you can eliminate this overhead by forcing the packer to use the appropriate type, which will save it from running the auto-detection routine. Another option is to explicitly specify the value type. The library provides 2 auxiliary classes for this,Map
andBin
. Check the "Custom types" section below for details.
Examples:
// detect str/bin type and pack PHP 64-bit floats (doubles) to MP 32-bit floats
$packer = new Packer(PackOptions::DETECT_STR_BIN | PackOptions::FORCE_FLOAT32);
// these will throw MessagePack\Exception\InvalidOptionException
$packer = new Packer(PackOptions::FORCE_STR | PackOptions::FORCE_BIN);
$packer = new Packer(PackOptions::FORCE_FLOAT32 | PackOptions::FORCE_FLOAT64);
To unpack data you can either use an instance of a BufferUnpacker
:
$unpacker = new BufferUnpacker();
$unpacker->reset($packed);
$value = $unpacker->unpack();
or call a static method on the MessagePack
class:
$value = MessagePack::unpack($packed);
If the packed data is received in chunks (e.g. when reading from a stream), use the tryUnpack
method, which attempts to unpack data and returns an array of unpacked messages (if any) instead of throwing an InsufficientDataException
:
while ($chunk = ...) {
$unpacker->append($chunk);
if ($messages = $unpacker->tryUnpack()) {
return $messages;
}
}
If you want to unpack from a specific position in a buffer, use seek
:
$unpacker->seek(42); // set position equal to 42 bytes
$unpacker->seek(-8); // set position to 8 bytes before the end of the buffer
To skip bytes from the current position, use skip
:
$unpacker->skip(10); // set position to 10 bytes ahead of the current position
To get the number of remaining (unread) bytes in the buffer:
$unreadBytesCount = $unpacker->getRemainingCount();
To check whether the buffer has unread data:
$hasUnreadBytes = $unpacker->hasRemaining();
If needed, you can remove already read data from the buffer by calling:
$releasedBytesCount = $unpacker->release();
With the read
method you can read raw (packed) data:
$packedData = $unpacker->read(2); // read 2 bytes
Besides the above methods BufferUnpacker
provides type-specific unpacking methods, namely:
$unpacker->unpackNil(); // PHP null
$unpacker->unpackBool(); // PHP bool
$unpacker->unpackInt(); // PHP int
$unpacker->unpackFloat(); // PHP float
$unpacker->unpackStr(); // PHP UTF-8 string
$unpacker->unpackBin(); // PHP binary string
$unpacker->unpackArray(); // PHP sequential array
$unpacker->unpackMap(); // PHP associative array
$unpacker->unpackExt(); // PHP MessagePack\Type\Ext object
The BufferUnpacker
object supports a number of bitmask-based options for fine-tuning the unpacking process (defaults are in bold):
Name | Description |
---|---|
BIGINT_AS_STR | Converts overflowed integers to strings [1] |
BIGINT_AS_GMP | Converts overflowed integers to GMP objects [2] |
BIGINT_AS_DEC | Converts overflowed integers to Decimal\Decimal objects [3] |
1. The binary MessagePack format has unsigned 64-bit as its largest integer data type, but PHP does not support such integers, which means that an overflow can occur during unpacking.
2. Make sure the GMP extension is enabled.
3. Make sure the Decimal extension is enabled.
Examples:
$packedUint64 = "\xcf"."\xff\xff\xff\xff"."\xff\xff\xff\xff";
$unpacker = new BufferUnpacker($packedUint64);
var_dump($unpacker->unpack()); // string(20) "18446744073709551615"
$unpacker = new BufferUnpacker($packedUint64, UnpackOptions::BIGINT_AS_GMP);
var_dump($unpacker->unpack()); // object(GMP) {...}
$unpacker = new BufferUnpacker($packedUint64, UnpackOptions::BIGINT_AS_DEC);
var_dump($unpacker->unpack()); // object(Decimal\Decimal) {...}
In addition to the basic types, the library provides functionality to serialize and deserialize arbitrary types. This can be done in several ways, depending on your use case. Let's take a look at them.
If you need to serialize an instance of one of your classes into one of the basic MessagePack types, the best way to do this is to implement the CanBePacked interface in the class. A good example of such a class is the Map
type class that comes with the library. This type is useful when you want to explicitly specify that a given PHP array should be packed as a MessagePack map without triggering an automatic type detection routine:
$packer = new Packer();
$packedMap = $packer->pack(new Map([1, 2, 3]));
$packedArray = $packer->pack([1, 2, 3]);
More type examples can be found in the src/Type directory.
As with type objects, type transformers are only responsible for serializing values. They should be used when you need to serialize a value that does not implement the CanBePacked interface. Examples of such values could be instances of built-in or third-party classes that you don't own, or non-objects such as resources.
A transformer class must implement the CanPack interface. To use a transformer, it must first be registered in the packer. Here is an example of how to serialize PHP streams into the MessagePack bin
format type using one of the supplied transformers, StreamTransformer
:
$packer = new Packer(null, [new StreamTransformer()]);
$packedBin = $packer->pack(fopen('/path/to/file', 'r+'));
More type transformer examples can be found in the src/TypeTransformer directory.
In contrast to the cases described above, extensions are intended to handle extension types and are responsible for both serialization and deserialization of values (types).
An extension class must implement the Extension interface. To use an extension, it must first be registered in the packer and the unpacker.
The MessagePack specification divides extension types into two groups: predefined and application-specific. Currently, there is only one predefined type in the specification, Timestamp.
Timestamp
The Timestamp extension type is a predefined type. Support for this type in the library is done through the TimestampExtension
class. This class is responsible for handling Timestamp
objects, which represent the number of seconds and optional adjustment in nanoseconds:
$timestampExtension = new TimestampExtension();
$packer = new Packer();
$packer = $packer->extendWith($timestampExtension);
$unpacker = new BufferUnpacker();
$unpacker = $unpacker->extendWith($timestampExtension);
$packedTimestamp = $packer->pack(Timestamp::now());
$timestamp = $unpacker->reset($packedTimestamp)->unpack();
$seconds = $timestamp->getSeconds();
$nanoseconds = $timestamp->getNanoseconds();
When using the MessagePack
class, the Timestamp extension is already registered:
$packedTimestamp = MessagePack::pack(Timestamp::now());
$timestamp = MessagePack::unpack($packedTimestamp);
Application-specific extensions
In addition, the format can be extended with your own types. For example, to make the built-in PHP DateTime
objects first-class citizens in your code, you can create a corresponding extension, as shown in the example. Please note, that custom extensions have to be registered with a unique extension ID (an integer from 0
to 127
).
More extension examples can be found in the examples/MessagePack directory.
To learn more about how extension types can be useful, check out this article.
If an error occurs during packing/unpacking, a PackingFailedException
or an UnpackingFailedException
will be thrown, respectively. In addition, an InsufficientDataException
can be thrown during unpacking.
An InvalidOptionException
will be thrown in case an invalid option (or a combination of mutually exclusive options) is used.
Run tests as follows:
vendor/bin/phpunit
Also, if you already have Docker installed, you can run the tests in a docker container. First, create a container:
./dockerfile.sh | docker build -t msgpack -
The command above will create a container named msgpack
with PHP 8.1 runtime. You may change the default runtime by defining the PHP_IMAGE
environment variable:
PHP_IMAGE='php:8.0-cli' ./dockerfile.sh | docker build -t msgpack -
See a list of various images here.
Then run the unit tests:
docker run --rm -v $PWD:/msgpack -w /msgpack msgpack
To ensure that the unpacking works correctly with malformed/semi-malformed data, you can use a testing technique called Fuzzing. The library ships with a help file (target) for PHP-Fuzzer and can be used as follows:
php-fuzzer fuzz tests/fuzz_buffer_unpacker.php
To check performance, run:
php -n -dzend_extension=opcache.so \
-dpcre.jit=1 -dopcache.enable=1 -dopcache.enable_cli=1 \
tests/bench.php
Example output
Filter: MessagePack\Tests\Perf\Filter\ListFilter
Rounds: 3
Iterations: 100000
=============================================
Test/Target Packer BufferUnpacker
---------------------------------------------
nil .................. 0.0030 ........ 0.0139
false ................ 0.0037 ........ 0.0144
true ................. 0.0040 ........ 0.0137
7-bit uint #1 ........ 0.0052 ........ 0.0120
7-bit uint #2 ........ 0.0059 ........ 0.0114
7-bit uint #3 ........ 0.0061 ........ 0.0119
5-bit sint #1 ........ 0.0067 ........ 0.0126
5-bit sint #2 ........ 0.0064 ........ 0.0132
5-bit sint #3 ........ 0.0066 ........ 0.0135
8-bit uint #1 ........ 0.0078 ........ 0.0200
8-bit uint #2 ........ 0.0077 ........ 0.0212
8-bit uint #3 ........ 0.0086 ........ 0.0203
16-bit uint #1 ....... 0.0111 ........ 0.0271
16-bit uint #2 ....... 0.0115 ........ 0.0260
16-bit uint #3 ....... 0.0103 ........ 0.0273
32-bit uint #1 ....... 0.0116 ........ 0.0326
32-bit uint #2 ....... 0.0118 ........ 0.0332
32-bit uint #3 ....... 0.0127 ........ 0.0325
64-bit uint #1 ....... 0.0140 ........ 0.0277
64-bit uint #2 ....... 0.0134 ........ 0.0294
64-bit uint #3 ....... 0.0134 ........ 0.0281
8-bit int #1 ......... 0.0086 ........ 0.0241
8-bit int #2 ......... 0.0089 ........ 0.0225
8-bit int #3 ......... 0.0085 ........ 0.0229
16-bit int #1 ........ 0.0118 ........ 0.0280
16-bit int #2 ........ 0.0121 ........ 0.0270
16-bit int #3 ........ 0.0109 ........ 0.0274
32-bit int #1 ........ 0.0128 ........ 0.0346
32-bit int #2 ........ 0.0118 ........ 0.0339
32-bit int #3 ........ 0.0135 ........ 0.0368
64-bit int #1 ........ 0.0138 ........ 0.0276
64-bit int #2 ........ 0.0132 ........ 0.0286
64-bit int #3 ........ 0.0137 ........ 0.0274
64-bit int #4 ........ 0.0180 ........ 0.0285
64-bit float #1 ...... 0.0134 ........ 0.0284
64-bit float #2 ...... 0.0125 ........ 0.0275
64-bit float #3 ...... 0.0126 ........ 0.0283
fix string #1 ........ 0.0035 ........ 0.0133
fix string #2 ........ 0.0094 ........ 0.0216
fix string #3 ........ 0.0094 ........ 0.0222
fix string #4 ........ 0.0091 ........ 0.0241
8-bit string #1 ...... 0.0122 ........ 0.0301
8-bit string #2 ...... 0.0118 ........ 0.0304
8-bit string #3 ...... 0.0119 ........ 0.0315
16-bit string #1 ..... 0.0150 ........ 0.0388
16-bit string #2 ..... 0.1545 ........ 0.1665
32-bit string ........ 0.1570 ........ 0.1756
wide char string #1 .. 0.0091 ........ 0.0236
wide char string #2 .. 0.0122 ........ 0.0313
8-bit binary #1 ...... 0.0100 ........ 0.0302
8-bit binary #2 ...... 0.0123 ........ 0.0324
8-bit binary #3 ...... 0.0126 ........ 0.0327
16-bit binary ........ 0.0168 ........ 0.0372
32-bit binary ........ 0.1588 ........ 0.1754
fix array #1 ......... 0.0042 ........ 0.0131
fix array #2 ......... 0.0294 ........ 0.0367
fix array #3 ......... 0.0412 ........ 0.0472
16-bit array #1 ...... 0.1378 ........ 0.1596
16-bit array #2 ........... S ............. S
32-bit array .............. S ............. S
complex array ........ 0.1865 ........ 0.2283
fix map #1 ........... 0.0725 ........ 0.1048
fix map #2 ........... 0.0319 ........ 0.0405
fix map #3 ........... 0.0356 ........ 0.0665
fix map #4 ........... 0.0465 ........ 0.0497
16-bit map #1 ........ 0.2540 ........ 0.3028
16-bit map #2 ............. S ............. S
32-bit map ................ S ............. S
complex map .......... 0.2372 ........ 0.2710
fixext 1 ............. 0.0283 ........ 0.0358
fixext 2 ............. 0.0291 ........ 0.0371
fixext 4 ............. 0.0302 ........ 0.0355
fixext 8 ............. 0.0288 ........ 0.0384
fixext 16 ............ 0.0293 ........ 0.0359
8-bit ext ............ 0.0302 ........ 0.0439
16-bit ext ........... 0.0334 ........ 0.0499
32-bit ext ........... 0.1845 ........ 0.1888
32-bit timestamp #1 .. 0.0337 ........ 0.0547
32-bit timestamp #2 .. 0.0335 ........ 0.0560
64-bit timestamp #1 .. 0.0371 ........ 0.0575
64-bit timestamp #2 .. 0.0374 ........ 0.0542
64-bit timestamp #3 .. 0.0356 ........ 0.0533
96-bit timestamp #1 .. 0.0362 ........ 0.0699
96-bit timestamp #2 .. 0.0381 ........ 0.0701
96-bit timestamp #3 .. 0.0367 ........ 0.0687
=============================================
Total 2.7618 4.0820
Skipped 4 4
Failed 0 0
Ignored 0 0
With JIT:
php -n -dzend_extension=opcache.so \
-dpcre.jit=1 -dopcache.jit_buffer_size=64M -dopcache.jit=tracing -dopcache.enable=1 -dopcache.enable_cli=1 \
tests/bench.php
Example output
Filter: MessagePack\Tests\Perf\Filter\ListFilter
Rounds: 3
Iterations: 100000
=============================================
Test/Target Packer BufferUnpacker
---------------------------------------------
nil .................. 0.0005 ........ 0.0054
false ................ 0.0004 ........ 0.0059
true ................. 0.0004 ........ 0.0059
7-bit uint #1 ........ 0.0010 ........ 0.0047
7-bit uint #2 ........ 0.0010 ........ 0.0046
7-bit uint #3 ........ 0.0010 ........ 0.0046
5-bit sint #1 ........ 0.0025 ........ 0.0046
5-bit sint #2 ........ 0.0023 ........ 0.0046
5-bit sint #3 ........ 0.0024 ........ 0.0045
8-bit uint #1 ........ 0.0043 ........ 0.0081
8-bit uint #2 ........ 0.0043 ........ 0.0079
8-bit uint #3 ........ 0.0041 ........ 0.0080
16-bit uint #1 ....... 0.0064 ........ 0.0095
16-bit uint #2 ....... 0.0064 ........ 0.0091
16-bit uint #3 ....... 0.0064 ........ 0.0094
32-bit uint #1 ....... 0.0085 ........ 0.0114
32-bit uint #2 ....... 0.0077 ........ 0.0122
32-bit uint #3 ....... 0.0077 ........ 0.0120
64-bit uint #1 ....... 0.0085 ........ 0.0159
64-bit uint #2 ....... 0.0086 ........ 0.0157
64-bit uint #3 ....... 0.0086 ........ 0.0158
8-bit int #1 ......... 0.0042 ........ 0.0080
8-bit int #2 ......... 0.0042 ........ 0.0080
8-bit int #3 ......... 0.0042 ........ 0.0081
16-bit int #1 ........ 0.0065 ........ 0.0095
16-bit int #2 ........ 0.0065 ........ 0.0090
16-bit int #3 ........ 0.0056 ........ 0.0085
32-bit int #1 ........ 0.0067 ........ 0.0107
32-bit int #2 ........ 0.0066 ........ 0.0106
32-bit int #3 ........ 0.0063 ........ 0.0104
64-bit int #1 ........ 0.0072 ........ 0.0162
64-bit int #2 ........ 0.0073 ........ 0.0174
64-bit int #3 ........ 0.0072 ........ 0.0164
64-bit int #4 ........ 0.0077 ........ 0.0161
64-bit float #1 ...... 0.0053 ........ 0.0135
64-bit float #2 ...... 0.0053 ........ 0.0135
64-bit float #3 ...... 0.0052 ........ 0.0135
fix string #1 ....... -0.0002 ........ 0.0044
fix string #2 ........ 0.0035 ........ 0.0067
fix string #3 ........ 0.0035 ........ 0.0077
fix string #4 ........ 0.0033 ........ 0.0078
8-bit string #1 ...... 0.0059 ........ 0.0110
8-bit string #2 ...... 0.0063 ........ 0.0121
8-bit string #3 ...... 0.0064 ........ 0.0124
16-bit string #1 ..... 0.0099 ........ 0.0146
16-bit string #2 ..... 0.1522 ........ 0.1474
32-bit string ........ 0.1511 ........ 0.1483
wide char string #1 .. 0.0039 ........ 0.0084
wide char string #2 .. 0.0073 ........ 0.0123
8-bit binary #1 ...... 0.0040 ........ 0.0112
8-bit binary #2 ...... 0.0075 ........ 0.0123
8-bit binary #3 ...... 0.0077 ........ 0.0129
16-bit binary ........ 0.0096 ........ 0.0145
32-bit binary ........ 0.1535 ........ 0.1479
fix array #1 ......... 0.0008 ........ 0.0061
fix array #2 ......... 0.0121 ........ 0.0165
fix array #3 ......... 0.0193 ........ 0.0222
16-bit array #1 ...... 0.0607 ........ 0.0479
16-bit array #2 ........... S ............. S
32-bit array .............. S ............. S
complex array ........ 0.0749 ........ 0.0824
fix map #1 ........... 0.0329 ........ 0.0431
fix map #2 ........... 0.0161 ........ 0.0189
fix map #3 ........... 0.0205 ........ 0.0262
fix map #4 ........... 0.0252 ........ 0.0205
16-bit map #1 ........ 0.1016 ........ 0.0927
16-bit map #2 ............. S ............. S
32-bit map ................ S ............. S
complex map .......... 0.1096 ........ 0.1030
fixext 1 ............. 0.0157 ........ 0.0161
fixext 2 ............. 0.0175 ........ 0.0183
fixext 4 ............. 0.0156 ........ 0.0185
fixext 8 ............. 0.0163 ........ 0.0184
fixext 16 ............ 0.0164 ........ 0.0182
8-bit ext ............ 0.0158 ........ 0.0207
16-bit ext ........... 0.0203 ........ 0.0219
32-bit ext ........... 0.1614 ........ 0.1539
32-bit timestamp #1 .. 0.0195 ........ 0.0249
32-bit timestamp #2 .. 0.0188 ........ 0.0260
64-bit timestamp #1 .. 0.0207 ........ 0.0281
64-bit timestamp #2 .. 0.0212 ........ 0.0291
64-bit timestamp #3 .. 0.0207 ........ 0.0295
96-bit timestamp #1 .. 0.0222 ........ 0.0358
96-bit timestamp #2 .. 0.0228 ........ 0.0353
96-bit timestamp #3 .. 0.0210 ........ 0.0319
=============================================
Total 1.6432 1.9674
Skipped 4 4
Failed 0 0
Ignored 0 0
You may change default benchmark settings by defining the following environment variables:
Name | Default |
---|---|
MP_BENCH_TARGETS | pure_p,pure_u , see a list of available targets |
MP_BENCH_ITERATIONS | 100_000 |
MP_BENCH_DURATION | not set |
MP_BENCH_ROUNDS | 3 |
MP_BENCH_TESTS | -@slow , see a list of available tests |
For example:
export MP_BENCH_TARGETS=pure_p
export MP_BENCH_ITERATIONS=1000000
export MP_BENCH_ROUNDS=5
# a comma separated list of test names
export MP_BENCH_TESTS='complex array, complex map'
# or a group name
# export MP_BENCH_TESTS='-@slow' // @pecl_comp
# or a regexp
# export MP_BENCH_TESTS='/complex (array|map)/'
Another example, benchmarking both the library and the PECL extension:
MP_BENCH_TARGETS=pure_p,pure_u,pecl_p,pecl_u \
php -n -dextension=msgpack.so -dzend_extension=opcache.so \
-dpcre.jit=1 -dopcache.enable=1 -dopcache.enable_cli=1 \
tests/bench.php
Example output
Filter: MessagePack\Tests\Perf\Filter\ListFilter
Rounds: 3
Iterations: 100000
===========================================================================
Test/Target Packer BufferUnpacker msgpack_pack msgpack_unpack
---------------------------------------------------------------------------
nil .................. 0.0031 ........ 0.0141 ...... 0.0055 ........ 0.0064
false ................ 0.0039 ........ 0.0154 ...... 0.0056 ........ 0.0053
true ................. 0.0038 ........ 0.0139 ...... 0.0056 ........ 0.0044
7-bit uint #1 ........ 0.0061 ........ 0.0110 ...... 0.0059 ........ 0.0046
7-bit uint #2 ........ 0.0065 ........ 0.0119 ...... 0.0042 ........ 0.0029
7-bit uint #3 ........ 0.0054 ........ 0.0117 ...... 0.0045 ........ 0.0025
5-bit sint #1 ........ 0.0047 ........ 0.0103 ...... 0.0038 ........ 0.0022
5-bit sint #2 ........ 0.0048 ........ 0.0117 ...... 0.0038 ........ 0.0022
5-bit sint #3 ........ 0.0046 ........ 0.0102 ...... 0.0038 ........ 0.0023
8-bit uint #1 ........ 0.0063 ........ 0.0174 ...... 0.0039 ........ 0.0031
8-bit uint #2 ........ 0.0063 ........ 0.0167 ...... 0.0040 ........ 0.0029
8-bit uint #3 ........ 0.0063 ........ 0.0168 ...... 0.0039 ........ 0.0030
16-bit uint #1 ....... 0.0092 ........ 0.0222 ...... 0.0049 ........ 0.0030
16-bit uint #2 ....... 0.0096 ........ 0.0227 ...... 0.0042 ........ 0.0046
16-bit uint #3 ....... 0.0123 ........ 0.0274 ...... 0.0059 ........ 0.0051
32-bit uint #1 ....... 0.0136 ........ 0.0331 ...... 0.0060 ........ 0.0048
32-bit uint #2 ....... 0.0130 ........ 0.0336 ...... 0.0070 ........ 0.0048
32-bit uint #3 ....... 0.0127 ........ 0.0329 ...... 0.0051 ........ 0.0048
64-bit uint #1 ....... 0.0126 ........ 0.0268 ...... 0.0055 ........ 0.0049
64-bit uint #2 ....... 0.0135 ........ 0.0281 ...... 0.0052 ........ 0.0046
64-bit uint #3 ....... 0.0131 ........ 0.0274 ...... 0.0069 ........ 0.0044
8-bit int #1 ......... 0.0077 ........ 0.0236 ...... 0.0058 ........ 0.0044
8-bit int #2 ......... 0.0087 ........ 0.0244 ...... 0.0058 ........ 0.0048
8-bit int #3 ......... 0.0084 ........ 0.0241 ...... 0.0055 ........ 0.0049
16-bit int #1 ........ 0.0112 ........ 0.0271 ...... 0.0048 ........ 0.0045
16-bit int #2 ........ 0.0124 ........ 0.0292 ...... 0.0057 ........ 0.0049
16-bit int #3 ........ 0.0118 ........ 0.0270 ...... 0.0058 ........ 0.0050
32-bit int #1 ........ 0.0137 ........ 0.0366 ...... 0.0058 ........ 0.0051
32-bit int #2 ........ 0.0133 ........ 0.0366 ...... 0.0056 ........ 0.0049
32-bit int #3 ........ 0.0129 ........ 0.0350 ...... 0.0052 ........ 0.0048
64-bit int #1 ........ 0.0145 ........ 0.0254 ...... 0.0034 ........ 0.0025
64-bit int #2 ........ 0.0097 ........ 0.0214 ...... 0.0034 ........ 0.0025
64-bit int #3 ........ 0.0096 ........ 0.0287 ...... 0.0059 ........ 0.0050
64-bit int #4 ........ 0.0143 ........ 0.0277 ...... 0.0059 ........ 0.0046
64-bit float #1 ...... 0.0134 ........ 0.0281 ...... 0.0057 ........ 0.0052
64-bit float #2 ...... 0.0141 ........ 0.0281 ...... 0.0057 ........ 0.0050
64-bit float #3 ...... 0.0144 ........ 0.0282 ...... 0.0057 ........ 0.0050
fix string #1 ........ 0.0036 ........ 0.0143 ...... 0.0066 ........ 0.0053
fix string #2 ........ 0.0107 ........ 0.0222 ...... 0.0065 ........ 0.0068
fix string #3 ........ 0.0116 ........ 0.0245 ...... 0.0063 ........ 0.0069
fix string #4 ........ 0.0105 ........ 0.0253 ...... 0.0083 ........ 0.0077
8-bit string #1 ...... 0.0126 ........ 0.0318 ...... 0.0075 ........ 0.0088
8-bit string #2 ...... 0.0121 ........ 0.0295 ...... 0.0076 ........ 0.0086
8-bit string #3 ...... 0.0125 ........ 0.0293 ...... 0.0130 ........ 0.0093
16-bit string #1 ..... 0.0159 ........ 0.0368 ...... 0.0117 ........ 0.0086
16-bit string #2 ..... 0.1547 ........ 0.1686 ...... 0.1516 ........ 0.1373
32-bit string ........ 0.1558 ........ 0.1729 ...... 0.1511 ........ 0.1396
wide char string #1 .. 0.0098 ........ 0.0237 ...... 0.0066 ........ 0.0065
wide char string #2 .. 0.0128 ........ 0.0291 ...... 0.0061 ........ 0.0082
8-bit binary #1 ........... I ............. I ........... F ............. I
8-bit binary #2 ........... I ............. I ........... F ............. I
8-bit binary #3 ........... I ............. I ........... F ............. I
16-bit binary ............. I ............. I ........... F ............. I
32-bit binary ............. I ............. I ........... F ............. I
fix array #1 ......... 0.0040 ........ 0.0129 ...... 0.0120 ........ 0.0058
fix array #2 ......... 0.0279 ........ 0.0390 ...... 0.0143 ........ 0.0165
fix array #3 ......... 0.0415 ........ 0.0463 ...... 0.0162 ........ 0.0187
16-bit array #1 ...... 0.1349 ........ 0.1628 ...... 0.0334 ........ 0.0341
16-bit array #2 ........... S ............. S ........... S ............. S
32-bit array .............. S ............. S ........... S ............. S
complex array ............. I ............. I ........... F ............. F
fix map #1 ................ I ............. I ........... F ............. I
fix map #2 ........... 0.0345 ........ 0.0391 ...... 0.0143 ........ 0.0168
fix map #3 ................ I ............. I ........... F ............. I
fix map #4 ........... 0.0459 ........ 0.0473 ...... 0.0151 ........ 0.0163
16-bit map #1 ........ 0.2518 ........ 0.2962 ...... 0.0400 ........ 0.0490
16-bit map #2 ............. S ............. S ........... S ............. S
32-bit map ................ S ............. S ........... S ............. S
complex map .......... 0.2380 ........ 0.2682 ...... 0.0545 ........ 0.0579
fixext 1 .................. I ............. I ........... F ............. F
fixext 2 .................. I ............. I ........... F ............. F
fixext 4 .................. I ............. I ........... F ............. F
fixext 8 .................. I ............. I ........... F ............. F
fixext 16 ................. I ............. I ........... F ............. F
8-bit ext ................. I ............. I ........... F ............. F
16-bit ext ................ I ............. I ........... F ............. F
32-bit ext ................ I ............. I ........... F ............. F
32-bit timestamp #1 ....... I ............. I ........... F ............. F
32-bit timestamp #2 ....... I ............. I ........... F ............. F
64-bit timestamp #1 ....... I ............. I ........... F ............. F
64-bit timestamp #2 ....... I ............. I ........... F ............. F
64-bit timestamp #3 ....... I ............. I ........... F ............. F
96-bit timestamp #1 ....... I ............. I ........... F ............. F
96-bit timestamp #2 ....... I ............. I ........... F ............. F
96-bit timestamp #3 ....... I ............. I ........... F ............. F
===========================================================================
Total 1.5625 2.3866 0.7735 0.7243
Skipped 4 4 4 4
Failed 0 0 24 17
Ignored 24 24 0 7
With JIT:
MP_BENCH_TARGETS=pure_p,pure_u,pecl_p,pecl_u \
php -n -dextension=msgpack.so -dzend_extension=opcache.so \
-dpcre.jit=1 -dopcache.jit_buffer_size=64M -dopcache.jit=tracing -dopcache.enable=1 -dopcache.enable_cli=1 \
tests/bench.php
Example output
Filter: MessagePack\Tests\Perf\Filter\ListFilter
Rounds: 3
Iterations: 100000
===========================================================================
Test/Target Packer BufferUnpacker msgpack_pack msgpack_unpack
---------------------------------------------------------------------------
nil .................. 0.0001 ........ 0.0052 ...... 0.0053 ........ 0.0042
false ................ 0.0007 ........ 0.0060 ...... 0.0057 ........ 0.0043
true ................. 0.0008 ........ 0.0060 ...... 0.0056 ........ 0.0041
7-bit uint #1 ........ 0.0031 ........ 0.0046 ...... 0.0062 ........ 0.0041
7-bit uint #2 ........ 0.0021 ........ 0.0043 ...... 0.0062 ........ 0.0041
7-bit uint #3 ........ 0.0022 ........ 0.0044 ...... 0.0061 ........ 0.0040
5-bit sint #1 ........ 0.0030 ........ 0.0048 ...... 0.0062 ........ 0.0040
5-bit sint #2 ........ 0.0032 ........ 0.0046 ...... 0.0062 ........ 0.0040
5-bit sint #3 ........ 0.0031 ........ 0.0046 ...... 0.0062 ........ 0.0040
8-bit uint #1 ........ 0.0054 ........ 0.0079 ...... 0.0062 ........ 0.0050
8-bit uint #2 ........ 0.0051 ........ 0.0079 ...... 0.0064 ........ 0.0044
8-bit uint #3 ........ 0.0051 ........ 0.0082 ...... 0.0062 ........ 0.0044
16-bit uint #1 ....... 0.0077 ........ 0.0094 ...... 0.0065 ........ 0.0045
16-bit uint #2 ....... 0.0077 ........ 0.0094 ...... 0.0063 ........ 0.0045
16-bit uint #3 ....... 0.0077 ........ 0.0095 ...... 0.0064 ........ 0.0047
32-bit uint #1 ....... 0.0088 ........ 0.0119 ...... 0.0063 ........ 0.0043
32-bit uint #2 ....... 0.0089 ........ 0.0117 ...... 0.0062 ........ 0.0039
32-bit uint #3 ....... 0.0089 ........ 0.0118 ...... 0.0063 ........ 0.0044
64-bit uint #1 ....... 0.0097 ........ 0.0155 ...... 0.0063 ........ 0.0045
64-bit uint #2 ....... 0.0095 ........ 0.0153 ...... 0.0061 ........ 0.0045
64-bit uint #3 ....... 0.0096 ........ 0.0156 ...... 0.0063 ........ 0.0047
8-bit int #1 ......... 0.0053 ........ 0.0083 ...... 0.0062 ........ 0.0044
8-bit int #2 ......... 0.0052 ........ 0.0080 ...... 0.0062 ........ 0.0044
8-bit int #3 ......... 0.0052 ........ 0.0080 ...... 0.0062 ........ 0.0043
16-bit int #1 ........ 0.0089 ........ 0.0097 ...... 0.0069 ........ 0.0046
16-bit int #2 ........ 0.0075 ........ 0.0093 ...... 0.0063 ........ 0.0043
16-bit int #3 ........ 0.0075 ........ 0.0094 ...... 0.0062 ........ 0.0046
32-bit int #1 ........ 0.0086 ........ 0.0122 ...... 0.0063 ........ 0.0044
32-bit int #2 ........ 0.0087 ........ 0.0120 ...... 0.0066 ........ 0.0046
32-bit int #3 ........ 0.0086 ........ 0.0121 ...... 0.0060 ........ 0.0044
64-bit int #1 ........ 0.0096 ........ 0.0149 ...... 0.0060 ........ 0.0045
64-bit int #2 ........ 0.0096 ........ 0.0157 ...... 0.0062 ........ 0.0044
64-bit int #3 ........ 0.0096 ........ 0.0160 ...... 0.0063 ........ 0.0046
64-bit int #4 ........ 0.0097 ........ 0.0157 ...... 0.0061 ........ 0.0044
64-bit float #1 ...... 0.0079 ........ 0.0153 ...... 0.0056 ........ 0.0044
64-bit float #2 ...... 0.0079 ........ 0.0152 ...... 0.0057 ........ 0.0045
64-bit float #3 ...... 0.0079 ........ 0.0155 ...... 0.0057 ........ 0.0044
fix string #1 ........ 0.0010 ........ 0.0045 ...... 0.0071 ........ 0.0044
fix string #2 ........ 0.0048 ........ 0.0075 ...... 0.0070 ........ 0.0060
fix string #3 ........ 0.0048 ........ 0.0086 ...... 0.0068 ........ 0.0060
fix string #4 ........ 0.0050 ........ 0.0088 ...... 0.0070 ........ 0.0059
8-bit string #1 ...... 0.0081 ........ 0.0129 ...... 0.0069 ........ 0.0062
8-bit string #2 ...... 0.0086 ........ 0.0128 ...... 0.0069 ........ 0.0065
8-bit string #3 ...... 0.0086 ........ 0.0126 ...... 0.0115 ........ 0.0065
16-bit string #1 ..... 0.0105 ........ 0.0137 ...... 0.0128 ........ 0.0068
16-bit string #2 ..... 0.1510 ........ 0.1486 ...... 0.1526 ........ 0.1391
32-bit string ........ 0.1517 ........ 0.1475 ...... 0.1504 ........ 0.1370
wide char string #1 .. 0.0044 ........ 0.0085 ...... 0.0067 ........ 0.0057
wide char string #2 .. 0.0081 ........ 0.0125 ...... 0.0069 ........ 0.0063
8-bit binary #1 ........... I ............. I ........... F ............. I
8-bit binary #2 ........... I ............. I ........... F ............. I
8-bit binary #3 ........... I ............. I ........... F ............. I
16-bit binary ............. I ............. I ........... F ............. I
32-bit binary ............. I ............. I ........... F ............. I
fix array #1 ......... 0.0014 ........ 0.0059 ...... 0.0132 ........ 0.0055
fix array #2 ......... 0.0146 ........ 0.0156 ...... 0.0155 ........ 0.0148
fix array #3 ......... 0.0211 ........ 0.0229 ...... 0.0179 ........ 0.0180
16-bit array #1 ...... 0.0673 ........ 0.0498 ...... 0.0343 ........ 0.0388
16-bit array #2 ........... S ............. S ........... S ............. S
32-bit array .............. S ............. S ........... S ............. S
complex array ............. I ............. I ........... F ............. F
fix map #1 ................ I ............. I ........... F ............. I
fix map #2 ........... 0.0148 ........ 0.0180 ...... 0.0156 ........ 0.0179
fix map #3 ................ I ............. I ........... F ............. I
fix map #4 ........... 0.0252 ........ 0.0201 ...... 0.0214 ........ 0.0167
16-bit map #1 ........ 0.1027 ........ 0.0836 ...... 0.0388 ........ 0.0510
16-bit map #2 ............. S ............. S ........... S ............. S
32-bit map ................ S ............. S ........... S ............. S
complex map .......... 0.1104 ........ 0.1010 ...... 0.0556 ........ 0.0602
fixext 1 .................. I ............. I ........... F ............. F
fixext 2 .................. I ............. I ........... F ............. F
fixext 4 .................. I ............. I ........... F ............. F
fixext 8 .................. I ............. I ........... F ............. F
fixext 16 ................. I ............. I ........... F ............. F
8-bit ext ................. I ............. I ........... F ............. F
16-bit ext ................ I ............. I ........... F ............. F
32-bit ext ................ I ............. I ........... F ............. F
32-bit timestamp #1 ....... I ............. I ........... F ............. F
32-bit timestamp #2 ....... I ............. I ........... F ............. F
64-bit timestamp #1 ....... I ............. I ........... F ............. F
64-bit timestamp #2 ....... I ............. I ........... F ............. F
64-bit timestamp #3 ....... I ............. I ........... F ............. F
96-bit timestamp #1 ....... I ............. I ........... F ............. F
96-bit timestamp #2 ....... I ............. I ........... F ............. F
96-bit timestamp #3 ....... I ............. I ........... F ............. F
===========================================================================
Total 0.9642 1.0909 0.8224 0.7213
Skipped 4 4 4 4
Failed 0 0 24 17
Ignored 24 24 0 7
Note that the msgpack extension (v2.1.2) doesn't support ext, bin and UTF-8 str types.
The library is released under the MIT License. See the bundled LICENSE file for details.
Author: rybakit
Source Code: https://github.com/rybakit/msgpack.php
License: MIT License
1680761100
If you are a beginner and want to create a JavaScript Password Generator then this tutorial is for you. Here I have shown step-by-step and shared complete information on how to create a password generator using JavaScript.
JavaScript Password Generator will help you create the password of your choice. Earlier I showed you how to create JavaScript Random Password Generator. However, this design will give you the option to create a password manually.
This simple password generator will help you create the password you want. There are different options and controls. This will allow you to create the password you need.
You need JavaScript enabled to view it to make it. Here I have used HTML CSS and some amount of JavaScript.
First, a box was created on the webpage. In that box, I first created a display where the generated passwords can be seen.
Then an input box is created where you can control the width of the password. This means that the number of characters you want to create the password can be controlled by this slider.
Then there are the four smaller boxes. This select box created by the checkbox will help you to further customize your password. There is a button at the end of which clicks on which the password is generated and can be seen in the display.
If you want to create this Password Generator JavaScript then you must have a basic idea about HTML, CSS, and javascript.
But if you just want the source code then follow the part below the article. But if you are a beginner then follow the tutorial below.
This JavaScript Password Generator has a copy button. When you click on the Generate button, the password will be copied automatically.
I first created an area using the following HTML and CSS codes. In this area, you can see all the information of Password Generator with JavaScript.
<div id=”password-generator”>
</div>
The webpage has been designed using the following code. Here the background color of the webpage is blue.
* {
box-sizing: border-box;
font-family: sans-serif;
}
body {
overflow: hidden;
margin: 0;
padding: 0;
display: flex;
align-items: center;
text-align: center;
height: 100vh;
background: #0976d5;
}
I have used the background color of this box as white and width: 500px. Box shadows have been used to enhance beauty.
#password-generator {
padding: 2rem;
margin: 0 auto;
width: 500px;
border-radius: 3px;
box-shadow: 0 0 2px #1f1f1f;
border: 3px solid #d5d4ff;
position: relative;
background: white;
white-space: nowrap;
}
Now we have created a display that will help to see the generated passwords. HTML’s input function has been used to create this box.
Box-shadow has been used to enhance the background white color and beauty of the box. Its box has no specific size. It will determine its own size depending on the amount of padding.
<input value=”Password generator” id=”password-output”>
input {
border: none;
background: transparent;
outline: none;
}
#password-output {
text-align: center;
font-size: 2rem;
margin: 0 auto 1.2rem;
width: 100%;
color: rgb(2, 91, 164);
padding: 5px;
box-shadow: 0 0 20px rgba(0,139,253,0.45);
}
Now a range slider has been created in this JavaScript Password Generator. I have used two input boxes here. The first input box to create the slider and the second input box to create the display.
When you change the value of this range, the value in that display will change. The input boxes are connected to each other using JavaScript.
<div class=”range”>
<input type=”range” min=”4″ max=”24″ step=”1″ value=”8″ id=”password-length”
oninput=”document.getElementById(‘display-password-length’).value=this.value”>
<input type=”text” value=”8″ maxlength=”2″ id=”display-password-length”
oninput=”document.getElementById(‘password-length’).value=this.value”>
</div>
#password-generator .range {
justify-content: space-between;
margin-top: 20px;
margin-bottom: 60px;
max-width: 70%;
margin-left: 15%;
padding: .4rem 1rem .8rem 2.5rem;
border: 1.5px solid rgb(8, 84, 181);
}
#password-generator .range input[type=range] {
-webkit-appearance: none;
appearance: none;
width: 40%;
max-width: 100%;
height: 15px;
padding: 0px;
background: #7a7a82;
outline: none;
opacity: 0.7;
-webkit-transition: 0.2s;
transition: opacity 0.2s;
box-shadow: 0 2px 35px rgba(0, 0, 0, 0.4555);
border-radius: 10px;
cursor: pointer;
scroll-behavior: smooth;
z-index: 1;
}
The Range Slider button has been designed using the following codes. Here I am using the background color blue of the button.
.range input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: rgb(9, 71, 222);
cursor: pointer;
border-radius: 18px;
transition: 0.5s ease;
}
The size of the display is determined using the CSS below. Font-size: 1.4rem has been used to increase the display’s width: 80px and text size.
body #password-generator .range #display-password-length {
text-align: center;
font-size: 1.4rem;
width: 80px;
padding-top: 10px;
}
The select options have been created using the following codes. Here four inputs and four labels are used. There is a label for each input.
Those labels will help to understand which select box to select which value. You can customize your password using this select box.
<div class=”flex”>
<input type=”checkbox” id=”lowercase” checked=”checked”>
<label for=”lowercase”>a-z</label>
<input type=”checkbox” id=”uppercase”>
<label for=”uppercase”>A-Z</label>
<input type=”checkbox” id=”numbers”>
<label for=”numbers”>0-9</label>
<input type=”checkbox” id=”symbols”>
<label for=”symbols”>!-?</label>
</div>
.flex {
margin: 1rem 1rem 2rem;
display: flex;
justify-content: space-between;
}
.flex input {
display: none;
}
.flex input:checked + label {
border: 2px solid rgb(205, 151, 12);
background: rgb(173, 144, 82);
filter: brightness(120%);
transform: scale(1.1);
}
.flex label {
border: 2px solid #0571bb;
border-radius: 4px;
padding: 0.6rem;
cursor: pointer;
font-size: 1.3rem;
text-align: center;
display: block;
width: 80px;
transition: 0.2s ease;
}
Now you need to create a button in Password Generator JavaScript. The password will be generated when the button is clicked.
Here the button function is used. The button’s background color is blue and the text color is white.
<button id=”generateButton” type=”button” onclick=”generatePassword()”>Generate</button>
#password-generator button {
outline: none;
background: #0f6cc3;
color: white;
border: none;
padding: 1rem 2rem;
margin: 0.5rem 0;
border-radius: 3px;
box-shadow: 1px 1px 6px 1px #8f8a8a;
text-transform: uppercase;
font-size: 1.2rem;
transition: 0.2s ease;
cursor: pointer;
}
#password-generator button:hover {
background: rgb(173, 118, 22);
}
I have basically designed this JavaScript Password Generator above. Now it’s time to activate this password generator using JavaScript.
JavaScript used here is a bit difficult. To understand these codes you need to have a basic idea about JavaScript.
//The global constant of the display id is set
const passwordOutput = document.getElementById(‘password-output’);
//The Lower characters used here are stored in the ‘dataLowercase’
const dataLowercase = “azertyuiopqsdfghjklmwxcvbn”.split(”);
//The Upper characters used here are stored in the ‘dataUppercase’
const dataUppercase = “AZERTYUIOPQSDFGHJKLMWXCVBN”.split(”);
//The Numbers used here are stored in the ‘dataNumbers’
const dataNumbers = “0123456789”.split(”);
//The Symbols used here are stored in the ‘dataSymbols’
const dataSymbols = “!@#$%^&*-_=+\|:;’,.>/?~”.split(”);
function generatePassword() {
//concat() is a string method that is used to concatenate strings together
const data = [].concat(
lowercase.checked ? dataLowercase : [],
uppercase.checked ? dataUppercase : [],
numbers.checked ? dataNumbers : [],
symbols.checked ? dataSymbols : []
);
//The value obtained from the range slider is stored in ‘password Length’
let passwordLength = parseInt(document.getElementById(‘display-password-length’).value);
let newPassword = ”;
//If you do not select a select box, you will see the following alert message
if (data.length === 0) {
passwordOutput.innerHTML = “Générateur de MDP”;
alert(‘Please check at least one criteria’);
return;
}
//It has been decided in which format the generated password will be displayed
//The Math. random() function returns a floating-point in the range 0 to less than 1
for (let i = 0; i < passwordLength; i++) {
newPassword += data[Math.floor(Math.random() * data.length)];
}
//Arrangements have been made to display the value of the new password in the display
passwordOutput.value = newPassword;
//The copy button has been activated.
//Clicking the Generate button will automatically copy the password
passwordOutput.select();
document.execCommand(‘copy’);
//After copying the password, the following text will appear in the button
generateButton.innerHTML = “Copied !”;
//Arrangements have been made to change the text of the button after 3.5 seconds
setTimeout(() => {generateButton.innerHTML = “Generator Again”}, 3500);
}
There are many users who just want the source code. Below I have given all the source code for them together. If you want to take all the code of this JavaScript Password Generator together then use the section below.
Here HTML, CSS, and javascript code are together. You copy those codes and add them to your HTML file. If you want previews and tutorials then follow the article above.
Hopefully using the above codes you have learned how to create this password generator using JavaScript. Earlier I shared a tutorial on Random Password Generator.
If you want to create a simple password generator then you can follow that tutorial. Below is a button that allows you to download the source code. If there is any problem, you can let me know by commenting.
Original article source at: https://foolishdeveloper.com/
1598839687
If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?
In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.
Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.
React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.
Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.
Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.
The popularity of React Native comes from its advantages. Some of its advantages are as follows:
Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.
React Native is very close to native. Consider the following aspects as described on the React Native website:
Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.
#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native
1680764941
如果您是初学者并想创建一个JavaScript 密码生成器,那么本教程适合您。在这里,我逐步展示并分享了有关如何使用 JavaScript 创建密码生成器的完整信息。
JavaScript 密码生成器将帮助您创建您选择的密码。之前我向您展示了如何创建JavaScript 随机密码生成器。但是,此设计将为您提供手动创建密码的选项。
这个简单的密码生成器将帮助您创建您想要的密码。有不同的选项和控件。这将允许您创建所需的密码。
您需要启用 JavaScript 才能查看它。这里我使用了 HTML CSS 和一些 JavaScript。
首先,在网页上创建了一个框。在那个框中,我首先创建了一个可以看到 生成的密码的显示。
然后创建一个输入框,您可以在其中控制密码的宽度。这意味着您可以通过此滑块控制要创建密码的字符数。
然后是四个较小的盒子。这个由复选框创建的选择框将帮助您进一步自定义您的密码。在其末尾有一个按钮,单击该按钮将生成密码并可以在显示屏上看到。
如果你想创建这个密码生成器 JavaScript,那么你必须对 HTML、CSS 和 javascript 有基本的了解。
但如果您只想要源代码,请按照文章下方的部分进行操作。但是,如果您是初学者,请按照下面的教程进行操作。
这个JavaScript 密码生成器有一个复制按钮。当您点击生成按钮时,密码将被自动复制。
我首先使用以下 HTML 和 CSS 代码创建了一个区域。在此区域中,您可以看到 Password Generator with JavaScript 的所有信息。
<div id=”password-generator”>
</div>
该网页是使用以下代码设计的。这里网页的背景颜色是蓝色。
* {
box-sizing: border-box;
font-family: sans-serif;
}
body {
overflow: hidden;
margin: 0;
padding: 0;
display: flex;
align-items: center;
text-align: center;
height: 100vh;
background: #0976d5;
}
我使用这个框的背景颜色为白色和宽度:500px。盒子阴影已被用来增强美感。
#password-generator {
padding: 2rem;
margin: 0 auto;
width: 500px;
border-radius: 3px;
box-shadow: 0 0 2px #1f1f1f;
border: 3px solid #d5d4ff;
position: relative;
background: white;
white-space: nowrap;
}
现在我们已经创建了一个显示,可以帮助查看生成的密码。HTML 的输入功能已用于创建此框。
box-shadow 已被用来增强盒子的背景白色和美感。它的盒子没有具体的尺寸。它将根据填充量确定自己的大小。
<input value=”Password generator” id=”password-output”>
input {
border: none;
background: transparent;
outline: none;
}
#password-output {
text-align: center;
font-size: 2rem;
margin: 0 auto 1.2rem;
width: 100%;
color: rgb(2, 91, 164);
padding: 5px;
box-shadow: 0 0 20px rgba(0,139,253,0.45);
}
现在,已在此JavaScript 密码生成器中创建了一个范围滑块。我在这里使用了两个输入框。第一个输入框创建滑块,第二个输入框创建显示。
当您更改此范围的值时,该显示中的值将更改。输入框使用 JavaScript 相互连接。
<div class=”range”>
<input type=”range” min=”4″ max=”24″ step=”1″ value=”8″ id=”password-length”
oninput=”document.getElementById(‘display-password-length’).value=this.value”>
<input type=”text” value=”8″ maxlength=”2″ id=”display-password-length”
oninput=”document.getElementById(‘password-length’).value=this.value”>
</div>
#password-generator .range {
justify-content: space-between;
margin-top: 20px;
margin-bottom: 60px;
max-width: 70%;
margin-left: 15%;
padding: .4rem 1rem .8rem 2.5rem;
border: 1.5px solid rgb(8, 84, 181);
}
#password-generator .range input[type=range] {
-webkit-appearance: none;
appearance: none;
width: 40%;
max-width: 100%;
height: 15px;
padding: 0px;
background: #7a7a82;
outline: none;
opacity: 0.7;
-webkit-transition: 0.2s;
transition: opacity 0.2s;
box-shadow: 0 2px 35px rgba(0, 0, 0, 0.4555);
border-radius: 10px;
cursor: pointer;
scroll-behavior: smooth;
z-index: 1;
}
Range Slider 按钮是使用以下代码设计的。这里我使用了按钮的背景色蓝色。
.range input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: rgb(9, 71, 222);
cursor: pointer;
border-radius: 18px;
transition: 0.5s ease;
}
显示的大小是使用下面的 CSS 确定的。字体大小:1.4rem 已用于增加显示宽度:80px 和文本大小。
body #password-generator .range #display-password-length {
text-align: center;
font-size: 1.4rem;
width: 80px;
padding-top: 10px;
}
选择选项是使用以下代码创建的。这里使用了四个输入和四个标签。每个输入都有一个标签。
这些标签将有助于理解哪个选择框选择哪个值。您可以使用此选择框自定义您的密码。
<div class=”flex”>
<input type=”checkbox” id=”lowercase” checked=”checked”>
<label for=”lowercase”>a-z</label>
<input type=”checkbox” id=”uppercase”>
<label for=”uppercase”>A-Z</label>
<input type=”checkbox” id=”numbers”>
<label for=”numbers”>0-9</label>
<input type=”checkbox” id=”symbols”>
<label for=”symbols”>!-?</label>
</div>
.flex {
margin: 1rem 1rem 2rem;
display: flex;
justify-content: space-between;
}
.flex input {
display: none;
}
.flex input:checked + label {
border: 2px solid rgb(205, 151, 12);
background: rgb(173, 144, 82);
filter: brightness(120%);
transform: scale(1.1);
}
.flex label {
border: 2px solid #0571bb;
border-radius: 4px;
padding: 0.6rem;
cursor: pointer;
font-size: 1.3rem;
text-align: center;
display: block;
width: 80px;
transition: 0.2s ease;
}
现在您需要在密码生成器 JavaScript 中创建一个按钮。单击按钮时将生成密码。
这里使用了按钮功能。按钮的背景颜色为蓝色,文本颜色为白色。
<button id=”generateButton” type=”button” onclick=”generatePassword()”>Generate</button>
#password-generator button {
outline: none;
background: #0f6cc3;
color: white;
border: none;
padding: 1rem 2rem;
margin: 0.5rem 0;
border-radius: 3px;
box-shadow: 1px 1px 6px 1px #8f8a8a;
text-transform: uppercase;
font-size: 1.2rem;
transition: 0.2s ease;
cursor: pointer;
}
#password-generator button:hover {
background: rgb(173, 118, 22);
}
我基本上已经设计了上面的这个JavaScript密码生成器。现在是时候使用 JavaScript激活这个密码生成器了。
这里使用的 JavaScript 有点难。要理解这些代码,您需要对 JavaScript 有一个基本的了解。
//The global constant of the display id is set
const passwordOutput = document.getElementById(‘password-output’);
//The Lower characters used here are stored in the ‘dataLowercase’
const dataLowercase = “azertyuiopqsdfghjklmwxcvbn”.split(”);
//The Upper characters used here are stored in the ‘dataUppercase’
const dataUppercase = “AZERTYUIOPQSDFGHJKLMWXCVBN”.split(”);
//The Numbers used here are stored in the ‘dataNumbers’
const dataNumbers = “0123456789”.split(”);
//The Symbols used here are stored in the ‘dataSymbols’
const dataSymbols = “!@#$%^&*-_=+\|:;’,.>/?~”.split(”);
function generatePassword() {
//concat() is a string method that is used to concatenate strings together
const data = [].concat(
lowercase.checked ? dataLowercase : [],
uppercase.checked ? dataUppercase : [],
numbers.checked ? dataNumbers : [],
symbols.checked ? dataSymbols : []
);
//The value obtained from the range slider is stored in ‘password Length’
let passwordLength = parseInt(document.getElementById(‘display-password-length’).value);
let newPassword = ”;
//If you do not select a select box, you will see the following alert message
if (data.length === 0) {
passwordOutput.innerHTML = “Générateur de MDP”;
alert(‘Please check at least one criteria’);
return;
}
//It has been decided in which format the generated password will be displayed
//The Math. random() function returns a floating-point in the range 0 to less than 1
for (let i = 0; i < passwordLength; i++) {
newPassword += data[Math.floor(Math.random() * data.length)];
}
//Arrangements have been made to display the value of the new password in the display
passwordOutput.value = newPassword;
//The copy button has been activated.
//Clicking the Generate button will automatically copy the password
passwordOutput.select();
document.execCommand(‘copy’);
//After copying the password, the following text will appear in the button
generateButton.innerHTML = “Copied !”;
//Arrangements have been made to change the text of the button after 3.5 seconds
setTimeout(() => {generateButton.innerHTML = “Generator Again”}, 3500);
}
有很多用户只想要源代码。下面我把它们的所有源码都一并给出了。如果您想将此 JavaScript密码生成器的所有代码放在一起,请使用下面的部分。
这里 HTML、CSS 和 javascript 代码在一起。您复制这些代码并将它们添加到您的 HTML 文件中。如果您想要预览和教程,请按照上面的文章进行操作。
希望通过上面的代码,您已经了解了如何使用 JavaScript 创建此密码生成器。早些时候我分享了一个关于随机密码生成器的教程。
如果您想创建一个简单的密码生成器,那么您可以按照该教程进行操作。下面是一个允许您下载源代码的按钮。如果有任何问题,您可以通过评论让我知道。
文章原文出处:https: //foolishdeveloper.com/
1680768780
Если вы новичок и хотите создать генератор паролей JavaScript , то это руководство для вас. Здесь я пошагово показал и поделился полной информацией о том, как создать генератор паролей с помощью JavaScript .
Генератор паролей JavaScript поможет вам создать пароль по вашему выбору. Ранее я показал вам, как создать генератор случайных паролей JavaScript . Однако этот дизайн даст вам возможность создать пароль вручную.
Этот простой генератор паролей поможет вам создать пароль, который вы хотите. Есть разные опции и элементы управления. Это позволит вам создать пароль, который вам нужен.
У вас должен быть включен JavaScript, чтобы просмотреть его, чтобы сделать это. Здесь я использовал HTML CSS и немного JavaScript.
Сначала на веб-странице был создан ящик. В этом поле я сначала создал дисплей, на котором можно увидеть сгенерированные пароли .
Затем создается поле ввода, в котором вы можете контролировать ширину пароля. Это означает, что количество символов, которые вы хотите создать в пароле, можно контролировать с помощью этого ползунка.
Затем идут четыре меньших коробки. Это поле выбора, созданное флажком, поможет вам дополнительно настроить свой пароль. В конце есть кнопка, при нажатии на которую генерируется пароль, который можно увидеть на дисплее.
Если вы хотите создать этот JavaScript-генератор паролей , у вас должно быть базовое представление о HTML, CSS и javascript.
Но если вам просто нужен исходный код, следуйте инструкциям ниже. Но если вы новичок, следуйте инструкциям ниже.
Этот генератор паролей JavaScript имеет кнопку копирования. При нажатии на кнопку «Создать» пароль будет скопирован автоматически.
Сначала я создал область, используя следующие коды HTML и CSS. В этой области вы можете увидеть всю информацию о генераторе паролей с JavaScript.
<div id=”password-generator”>
</div>
Веб-страница была разработана с использованием следующего кода. Здесь цвет фона веб-страницы синий.
* {
box-sizing: border-box;
font-family: sans-serif;
}
body {
overflow: hidden;
margin: 0;
padding: 0;
display: flex;
align-items: center;
text-align: center;
height: 100vh;
background: #0976d5;
}
Я использовал цвет фона этого поля как белый и ширину: 500 пикселей. Коробчатые тени использовались для усиления красоты.
#password-generator {
padding: 2rem;
margin: 0 auto;
width: 500px;
border-radius: 3px;
box-shadow: 0 0 2px #1f1f1f;
border: 3px solid #d5d4ff;
position: relative;
background: white;
white-space: nowrap;
}
Теперь мы создали дисплей, который поможет увидеть сгенерированные пароли. Для создания этого поля использовалась функция ввода HTML.
Box-shadow был использован для улучшения белого цвета фона и красоты блока. Его коробка не имеет определенного размера. Он сам определит свой размер в зависимости от количества отступов.
<input value=”Password generator” id=”password-output”>
input {
border: none;
background: transparent;
outline: none;
}
#password-output {
text-align: center;
font-size: 2rem;
margin: 0 auto 1.2rem;
width: 100%;
color: rgb(2, 91, 164);
padding: 5px;
box-shadow: 0 0 20px rgba(0,139,253,0.45);
}
Теперь в этом генераторе паролей JavaScript создан ползунок диапазона . Здесь я использовал два поля ввода. Первое поле ввода для создания ползунка и второе поле ввода для создания дисплея.
Когда вы измените значение этого диапазона, значение на этом дисплее изменится. Поля ввода связаны друг с другом с помощью JavaScript.
<div class=”range”>
<input type=”range” min=”4″ max=”24″ step=”1″ value=”8″ id=”password-length”
oninput=”document.getElementById(‘display-password-length’).value=this.value”>
<input type=”text” value=”8″ maxlength=”2″ id=”display-password-length”
oninput=”document.getElementById(‘password-length’).value=this.value”>
</div>
#password-generator .range {
justify-content: space-between;
margin-top: 20px;
margin-bottom: 60px;
max-width: 70%;
margin-left: 15%;
padding: .4rem 1rem .8rem 2.5rem;
border: 1.5px solid rgb(8, 84, 181);
}
#password-generator .range input[type=range] {
-webkit-appearance: none;
appearance: none;
width: 40%;
max-width: 100%;
height: 15px;
padding: 0px;
background: #7a7a82;
outline: none;
opacity: 0.7;
-webkit-transition: 0.2s;
transition: opacity 0.2s;
box-shadow: 0 2px 35px rgba(0, 0, 0, 0.4555);
border-radius: 10px;
cursor: pointer;
scroll-behavior: smooth;
z-index: 1;
}
Кнопка Range Slider была разработана с использованием следующих кодов. Здесь я использую синий цвет фона кнопки.
.range input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: rgb(9, 71, 222);
cursor: pointer;
border-radius: 18px;
transition: 0.5s ease;
}
Размер дисплея определяется с помощью приведенного ниже CSS. Размер шрифта: 1.4rem был использован для увеличения ширины экрана: 80 пикселей и размера текста.
body #password-generator .range #display-password-length {
text-align: center;
font-size: 1.4rem;
width: 80px;
padding-top: 10px;
}
Опции выбора были созданы с использованием следующих кодов. Здесь используются четыре входа и четыре метки. Для каждого входа есть метка.
Эти метки помогут понять, в каком поле выбора выбрать какое значение. Вы можете настроить свой пароль , используя это поле выбора.
<div class=”flex”>
<input type=”checkbox” id=”lowercase” checked=”checked”>
<label for=”lowercase”>a-z</label>
<input type=”checkbox” id=”uppercase”>
<label for=”uppercase”>A-Z</label>
<input type=”checkbox” id=”numbers”>
<label for=”numbers”>0-9</label>
<input type=”checkbox” id=”symbols”>
<label for=”symbols”>!-?</label>
</div>
.flex {
margin: 1rem 1rem 2rem;
display: flex;
justify-content: space-between;
}
.flex input {
display: none;
}
.flex input:checked + label {
border: 2px solid rgb(205, 151, 12);
background: rgb(173, 144, 82);
filter: brightness(120%);
transform: scale(1.1);
}
.flex label {
border: 2px solid #0571bb;
border-radius: 4px;
padding: 0.6rem;
cursor: pointer;
font-size: 1.3rem;
text-align: center;
display: block;
width: 80px;
transition: 0.2s ease;
}
Теперь вам нужно создать кнопку в генераторе паролей JavaScript. Пароль будет сгенерирован при нажатии на кнопку.
Здесь используется функция кнопки. Цвет фона кнопки — синий, а цвет текста — белый.
<button id=”generateButton” type=”button” onclick=”generatePassword()”>Generate</button>
#password-generator button {
outline: none;
background: #0f6cc3;
color: white;
border: none;
padding: 1rem 2rem;
margin: 0.5rem 0;
border-radius: 3px;
box-shadow: 1px 1px 6px 1px #8f8a8a;
text-transform: uppercase;
font-size: 1.2rem;
transition: 0.2s ease;
cursor: pointer;
}
#password-generator button:hover {
background: rgb(173, 118, 22);
}
Я в основном разработал этот генератор паролей JavaScript выше. Теперь пришло время активировать этот генератор паролей с помощью JavaScript .
Используемый здесь JavaScript немного сложен. Чтобы понять эти коды, вам нужно иметь базовое представление о JavaScript .
//The global constant of the display id is set
const passwordOutput = document.getElementById(‘password-output’);
//The Lower characters used here are stored in the ‘dataLowercase’
const dataLowercase = “azertyuiopqsdfghjklmwxcvbn”.split(”);
//The Upper characters used here are stored in the ‘dataUppercase’
const dataUppercase = “AZERTYUIOPQSDFGHJKLMWXCVBN”.split(”);
//The Numbers used here are stored in the ‘dataNumbers’
const dataNumbers = “0123456789”.split(”);
//The Symbols used here are stored in the ‘dataSymbols’
const dataSymbols = “!@#$%^&*-_=+\|:;’,.>/?~”.split(”);
function generatePassword() {
//concat() is a string method that is used to concatenate strings together
const data = [].concat(
lowercase.checked ? dataLowercase : [],
uppercase.checked ? dataUppercase : [],
numbers.checked ? dataNumbers : [],
symbols.checked ? dataSymbols : []
);
//The value obtained from the range slider is stored in ‘password Length’
let passwordLength = parseInt(document.getElementById(‘display-password-length’).value);
let newPassword = ”;
//If you do not select a select box, you will see the following alert message
if (data.length === 0) {
passwordOutput.innerHTML = “Générateur de MDP”;
alert(‘Please check at least one criteria’);
return;
}
//It has been decided in which format the generated password will be displayed
//The Math. random() function returns a floating-point in the range 0 to less than 1
for (let i = 0; i < passwordLength; i++) {
newPassword += data[Math.floor(Math.random() * data.length)];
}
//Arrangements have been made to display the value of the new password in the display
passwordOutput.value = newPassword;
//The copy button has been activated.
//Clicking the Generate button will automatically copy the password
passwordOutput.select();
document.execCommand(‘copy’);
//After copying the password, the following text will appear in the button
generateButton.innerHTML = “Copied !”;
//Arrangements have been made to change the text of the button after 3.5 seconds
setTimeout(() => {generateButton.innerHTML = “Generator Again”}, 3500);
}
Есть много пользователей, которые просто хотят исходный код. Ниже я привел весь исходный код для них вместе. Если вы хотите собрать весь код этого генератора паролей JavaScript вместе, воспользуйтесь разделом ниже.
Здесь HTML, CSS и код javascript объединены. Вы копируете эти коды и добавляете их в свой HTML-файл. Если вам нужны предварительные просмотры и учебные пособия, следуйте статье выше.
Надеюсь, используя приведенные выше коды, вы научились создавать этот генератор паролей с помощью JavaScript. Ранее я поделился туториалом по генератору случайных паролей .
Если вы хотите создать простой генератор паролей , вы можете следовать этому руководству. Ниже находится кнопка, позволяющая загрузить исходный код. Если есть какие-либо проблемы, вы можете сообщить мне, комментируя.
Оригинальный источник статьи: https://foolishdeveloper.com/