Skip to main content

Posts

PHP version of Cipher and SecretKeySpec [closed]

I have this Java code to encrypt a data using a key: static String IV = "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"; static String key = "somerandomkey0987"; public static String encrypt(String myData, String key) throws Exception { for(int i = 0; i < myData.length() % 16; ++i) { myData = myData + "\u0000"; } Cipher encripta = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE"); SecretKeySpec key = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); encripta.init(1, key, new IvParameterSpec(IV.getBytes("UTF-8"))); return byteToHex(encripta.doFinal(myData.getBytes("UTF-8"))); } public static String byteToHex(byte[] hash) { Formatter formatter = new Formatter(); byte[] var2 = hash; int var3 = hash.length; for(int var4 = 0; var4 < var3; ++var4) { byte b = var2[var4]; formatter....

How can i pass the title of the blog instead of the id in readmore in laravel

The route used to open the single blog: Route::get('/blog/{title}', 'EdificController@showblog');//single blog view The main blog blog route that lists all the blogs Route::get('/blog', 'EdificController@blog')->name('blog');//blog view The controller( front-end) to show the single blog public function showblog( $title) $blog = Blog::find($title); return view('edific.show-blog', compact('blog', 'blogcomments', 'blogreplies')); } The code to call the single blog via the read more: <a href="/blog/" class="post-meta">Read More</a> when i click the link i get the error Trying to get property 'image' of non-object (View: C:\laragon\www\edi-fic-1.0.0\resources\views\edific\show-blog.blade.php) What I want is that instead of calling the id e.g 1 ( http://127.0.0.1:8000/blog/**1** ) it should open using the title of the blog.The id should not be seen so...

memcached for legacy Laravel project

Have been struggling with installing memcached in my local environment (xampp). I'm working on a Laravel 5.1 project as a solo developer (I'm serving up the files using php artisan serve). I found this repo which supposedly has the .dll files (I'm running Windows 10). https://github.com/lifenglsf/php_memcached_dll/tree/master/3.1.4/php7.4/ts_x64 For reference, my PHP info: **Architecture: x64 PHP extension build: API20190902,TS,VC15 Compiler: Visual C++ 2017** PHP version: 7.4.22 I'm basically downloading the zip and copying the relevant files to my php\ext directory and referencing it in my .ini file (I've also tried absolute/relative paths), hence, extension=php_memcached.dll But, to no avail. I'm not sure what else to do. Thanks! source https://stackoverflow.com/questions/68987867/memcached-for-legacy-laravel-project

How can I show hide my logout button based on authentication without using Redux?

With the code below, the logout button will only show if I refresh the page upon being successfully being logged in. The functionality works as intended, so no issues there. Furthermore, I'd like to show the logout button on the navbar upon the user successfully logging in without refreshing page. I've tried many ways to solve this but to no avail. During my research, I came across something called Redux Persist but I'm unsure if it's worth using it in this scenario. Is there a way I can handle this without using Redux? I'm open to code improvements/suggestions of my code. Thanks in advance. import { Navbar, Nav, Container, Button } from 'react-bootstrap'; import axios from 'axios'; import { useHistory } from 'react-router-dom'; import {useEffect, useState} from "react"; const NavBar = () => { let history = useHistory(); const [loggedInUser, setLoggedInUser] = useState(""); useEffect(() => { ...

setState for set function in react hooks

I have a class component which has this operation: const notificationPreferencesEmailListIds: Set<number> = Array.isArray( notificationPreferences ) ? new Set( notificationPreferences.reduce( (acc: number[], item: INotificationPreference) => item.isUserSignedUp ? [...acc, item.emailListId] : acc, [] ) ) : new Set([]); this.state = { notificationPreferencesEmailListIds }; public setSubscriptionStatusById({ emailListId, operation, }: INotificationPreferencesStateSetter) { this.setState((prevState) => { prevState.notificationPreferencesEmailListIds[operation](emailListId); return { notificationPreferencesEmailListIds: prevState.notificationPreferencesEmailListIds, }; }); } private renderPreferences() { const { notificationPreferences } = this.props; return ( <div className="preferences"...

How can I attach a file to a drag event in JavaScript?

I would like to be able to drag from my web application onto another web application which expects a WAV file. I don't have any control over the target application. I can create the bytes of the WAV file, but the files property of the data transfer event is read only, so I don't see a way to add the file there. My makeWav function returns a DataView of the binary data. My code here fails because "files" is read only. this.div.addEventListener('dragstart', (ev: DragEvent) => { const data = WavMaker.makeWav( this.audioCtx, this.buffer, this.startOffsetS, this.durationS); const f = new File([data.buffer], "clip.wav"); ev.dataTransfer.files = [f]; // Fails because 'files' is read only. ev.dataTransfer.effectAllowed = "copy"; }); Maybe there is some way to do this with the setData function, but this uses a string for the data, not a binary object: const stringData = String.fromCharCode(...new Uint8Array(data.buffer...

need help color changeing shape isnt loading did i make an infanat loop?

im suposed to make one of those circles or squares that randomly change color but all its doing is constantly reloading i tryed changeing 'px' to ('px') but it only works with '10px' or '20px'and still wont show. function showPattern(){ const colorArray= ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']; let topPosition = 25; let leftPosition = 25; let width = 500; let height = 500; while(width > 50){ const randomColorIdx = Math.floor(Math.random() * colorArray.length); const newDiv = document.createElement("div"); newDiv.style.top = topPosition + 'px'; newDiv.style.left = leftPosition + 'px'; newDiv.style.width = width +'px'; newDiv.style.height = height + 'px'; newDiv.style.background = colorsArr[randomColorIdx]; document.body.appendChild(newDiv); ...